[R] Getting Rcpp SEXP data in C++

Joshua Ulrich josh.m.ulrich at gmail.com
Tue Sep 13 12:50:11 CEST 2011


Worik,

On Mon, Sep 12, 2011 at 10:54 PM, Worik R <worikr at gmail.com> wrote:
> Friends
>
> I am looking at Rcpp and I am a bit stuck on a simple matter.
>
Rcpp questions will likely get more attention on the Rcpp-devel list:
http://lists.r-forge.r-project.org/mailman/listinfo/rcpp-devel

> (I am calling R from c++, if there is a better way...)
>
> Given this simple example using the TTR package and the SMA function which
> returns a simple moving average....
>
> Rcpp::NumericVector rv;
>    for(int i = 0; i < 100; i++){
>      rv.push_back(rand());
>    }
>    Rcpp::Environment TTR("package:TTR");
>    Rcpp::Function sma = TTR["SMA"];
>    SEXP sma_res = sma(rv);
>
> How do I get the values of sma_res from a SEXP type into something
> useful in C++, like a vector<float>?
>
> Where can I find some documentation of SEXP?  I have tried googling it
> to no avail.
>
See the R Internals manual:
http://cran.r-project.org/doc/manuals/R-ints.html

> cheers
> Worik
>

Best,
--
Joshua Ulrich  |  FOSS Trading: www.fosstrading.com



More information about the R-help mailing list