[Rcpp-devel] Segfaults when declaring Vector types

Dirk Eddelbuettel edd at debian.org
Thu Apr 14 15:48:58 CEST 2011


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?



More information about the Rcpp-devel mailing list