I can't find any documentation about how to use the "forecast" R package from C++. Is anything available online?
I have not looked closely but as it depends on the CRAN packages Rcpp and RcppArmadillo (which I am involved and which facilitate C++ use from R), I'd say yes. You can probably poke around in the sources and find other entry points. It's open source, after all.
But if you asked for a well-defined pre-existing API for forecast, the answer may be no.
Edit: Oh, and the obvious plug for RInside which allows you to embed [a single instance of] R very easily inside your C++ application. It does this by wrapping the existing (but hard to use) embedding API in a much simpler to use C++ class which abstracts away all the handholding.
Related
I'm just getting started with Rcpp and wondering if somewhere out there a list of Rcpp sugar functions exists. In the process of translating some of my slow code to C/C++ I'll need functionality provided by base R functions like match, tabulate, and which.
According to Hadley's Advanced R book match is implemented and the Rcpp-sugar vignette lists a few more available functions though it doesn't seem comprehensive.
What I'm really wondering is: is there a way to find, in the documentation of the package, or elsewhere, what sweet-sweet-sweet functions are available and what I'll have to write for myself? With any other R package I'd go directly to R> help(package = "Rcpp") but that doesn't seem to be much help in this case.
As luck would have it, I started to document the Rcpp API in a more accessible manner than what is offered by the doxygen documentation. This documentation includes the Rcpp sugar set of functions alongside usable examples. I'm hopeful that Rcpp should ship with this documentation in the 0.13.0.
In the interim, you can view the source and contribute here:
https://github.com/coatless/rcpp-api/blob/master/rcpp-api-docs.Rmd
Or view a rendered version (that is lagged) here:
http://thecoatlessprofessor.com/programming/rcpp/unofficial-rcpp-api-docs/
I want to perform multinomial logistic regression [using glm()] and do some graphs [gplot()] in C++.
I'm not able to write a function for this kind of regression in C++, but maybe is possible to open R and call glm() function in order to performe it inside of C++, is it? how? I would appreciate any idea.
Thanks in advance!
Yes you can via the RInside project which provides you with a (very simple) class R which instantiates the R interpreter. You can then pass commands as (possibly multi-line) strings and evaluate via the REPL.
There are numerous examples in the package itself, and on different blog posts. As it uses Rcpp extensively, it is also covered in one chapter of the Rcpp book.
I recently asked this question https://softwareengineering.stackexchange.com/questions/129076/go-instead-of-c-c-with-cgo and got some very interesting input. However there's a mistake in my question: I assumed cgo could also be used to access c++ code but that's not possible. Instead you need to use SWIG.
The go faq says "The cgo program provides the mechanism for a “foreign function interface” to allow safe calling of C libraries from Go code. SWIG extends this capability to C++ libraries. "
my question:
Is it possible to access high-level c++ frameworks such as QT with SWIG + Go and get productive? I'd like to use Go as a "scripting language" to utilize c++ libraries.
Have you any experience with go and swig? Are there pitfalls I have to be aware of?
Update/Answer: I've asked this over IRC too and I think the question is solved:
SWIG is a rather clean way of interfacing c++ code from other languages. Sadly matching the types of c++ to something like go can be very complex and in most cases you have to specify the mapping yourself. That means that SWIG is a good way to leverage an existing codebase to reuse already written algorithms. However mapping a library like Qt to go will take you ages. Mind it's surely possible but you don't want to do it.
Those of you that came here for gui programming with go might want try go-gtk or the go version of wxWidgets.
Is it possible? Yes.
Can it be done in a reasonably short period of time? No.
If you go back and look at other projects that have taken large frameworks and tried to put an abstraction layer on it, you'll find most are "incomplete". You can probably make a fairly good start and get some initial wrappers in place, but generally even the work to get the simple cases solved takes time when there is a lot of underlying code to wrap, even with automated tools (which help, but are never a complete solution). And then... you get to the nasty remaining 10% that will take you forever (ok, a really really long time at least). And then think about how it's a changing target in the first place. Qt, for example, is about to release the next major rewrite.
Generally, it's safest to stick to the framework language that the framework was designed for. Though many have language extensions within the project itself. For example, for Qt you should check out QML, which provides (among many other things) a javascript binding to Qt. Sort of. But it might meet your "scripting" requirement.
A relevant update on this issue: it is now possible to interact with C++ using cgo with this CL, which is merged for Go 1.2. It is limited, however, to C-like functions calls, and classes, methods and C++ goodies are not supported (yet, I hope).
I would like to port the SpecialK Poker Hand evaluator to R. I think this should be relatively easy using the Rcpp package, but I have no idea where to begin.
The existing tutorials seem to focus on developing new C++ code for use in R. In this case, I have C++ that solves a problem, and I want to use this code in R with minimum hassle. If the code were one, self-contained function, I could compile and link it on the fly with inline, but this doesn't work here.
I guess this question has 2 parts:
Will I need to make any changes to the C++ source to make it compatible with Rcpp?
How do I call this code from R, given that it's not a small,
self-contained function I can compile and link dynamically using
inline?
I am also open to using the Java, python, or objective-C versions of the evaluator, but I don't think those will be easier to link to R.
Have you looked at Rcpp which makes it fairly painfree to combine R and C++?
Lots of packages use it to bring existing C++ code to R. You can also look at questions here under the [rcpp] tag. Fairly extensive documentation in the package, at my site and other places.
All,
I have been playing with the R math standalone library in C++. I quite like being able to generate random numbers and use distribution functions that I am comfortable with from R. My question is: is it possible to use the matrix operations (multiplication, transpose, inverse, Chol, etc) that are available in R in a standalone library? I don't see them in Rmath.h.
If matrix operations are available to use in standalone C++ code, it seems that the R API becomes the perfect open source computational engine. Are people using it in this fashion?
Thanks so much for your guidance and suggestions!
Most, if not all, of the things you mention are provided by LAPACK or BLAS Fortran code that R links to, not something R provides new code for itself.
If you are interested in using C++ with R, look at the Rcpp package by Dirk Eddelbuettel and Romain Francois. Dirk has also written the RcppArmadillo package as an interface to the Armadillo C++ linear algebra library that can do the matrix operations you mention.
Whether this is of use will depend on whether you are wanting to write separate C++ code that is accessed outside R, or interfacing C++ code that you access within R. Rcpp facilitates (greatly) the latter. Take a look at Armadillo directly if it is the former situation.
I think the original questions starts at the wrong end. There is no C++ in R, and no C++ API in R itself.
So if you want to access R matrix functions, you have to go through the R API -- which is a C layer and very much not C++.
Gavin in his answer (and comments) and Josh are spot-on: You probably want something like Armadillo for high-level matrix algebra. Armadillo (just like related libraries) eventually goes to BLAS and LAPACK --- as does R. [ Doug Bates usually reminds us that there is one important difference related to pivoted decompositions; this is touched upon in the fastLm() implementation and example in RcppArmadillo. ]
Lastly, Rcpp can help with both cases:
whether you want to extend R by calling C++ code you wrote, where Rcpp makes it easy to pass objects back and forth, or
whether you want to embed R inside your C++ application using RInside as Rcpp once again provides the glue
The rcpp-devel list is a good place for more in-depth discussions and examples.