Getting Rcpp SEXP data in C++

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Getting Rcpp SEXP data in C++

Worik R
Friends

I am looking at Rcpp and I am a bit stuck on a simple matter.

(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.

cheers
Worik

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Getting Rcpp SEXP data in C++

Joshua Ulrich
Worik,

On Mon, Sep 12, 2011 at 10:54 PM, Worik R <[hidden email]> 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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.