Hi again,

On 14 April 2011 at 23:20, Patrick Ye wrote:
| Hi Dirk,
| 
| Thanks so much for the reply, I really appreciate it.
| 
| I thought that I was misusing Rcpp, as all the examples I found seemed 
| to be for writing C++ functions to be used in R -- not accessing R 
| functions in C++.
| 
| Thanks so much for your suggestions on RInside, I just found out about 
| it a few minutes ago myself, and my code is no longer segfaulting. :)

Excellent :)
 
| One more question if you don't mind. Where can I find documentation on 
| accessing the member variables of an R instance using Rcpp? Let me give 
| you a concrete example of what I need to do.

Slowly work through the 10+ examples in examples/standard/ -- there are
examples for all cases.

The first approach is to use the parseEval() approach which returns the last
statement, as an R function would.  Rcpp then helps with the implicit or
explicit cast to whichever C++ type is suitable.

The second approach is ... simple lookup by name using [].
 
| I'm trying to use the stl function in R to calculate the seasonal, 
| trend, remainder and weight parameters of a time series object. I've 

You are spot on. Perfect use case: deploy something that R is strong at, and
pull it into C++.   Wanna contribute yet another example?  You will get
eternal fame by the Copyright line in that source file ;-)

| gotten as far as creating the time series object from a list of numbers, 
| and then passing the time series to the stl function using a 
| Rcpp::Language object, and then grabbing the results using the eval() 
| function of the Rcpp::Language object. If it was in R, I could access 
| the weights using notations like "foo$weights", and the time series 
| object as "foo$time.series".  If it was in rpy2, I could use the 
| dictionary notations to access the "weights" and "time.series" members 
| of stl's return value. However, I cannot seem to find any 
| function/notation in Rcpp that allows me to do the same thing.
| 
| I guess I could generate a string that represents all the things I need 
| to do in R, and use the parseEval function of the RInside object to get 
| the final results. However, that just doesn't seem to be very elegant. 
| Is there another way?

>From the top of my head, what I would do is to pass a string containing
several R commands to the embedded R instance. It should compute all values
of interest.  And the ones I'd want in C++ I'd then transfer one by one using
one of the approaches above.   Actually, you could even construct a big
encompassing list object in R, and pass that.  Rcpp then helps you decompose
it on the C++ side into individual pieces.   

More than one way to skin the cat...

Cheers, Dirk

-- 
Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com
_______________________________________________
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to