[Rcpp-devel] How to modifying the elements of a list in the global environment?

Dirk Eddelbuettel edd at debian.org
Sat Oct 20 14:55:53 CEST 2012


On 20 October 2012 at 03:11, Christian Gunning wrote:
| > What I would really do here is to create a simple struct or rather class that
| > upon initialization creates the workspace and holds it.
| >
| > Doesn't fit as easily in the inline paradigm though.
| 
| Can one place object definitions in includes and then use them in the
| body?  I'm rusty on inline -- I recall placing functions in includes,
| but I don't recall doing this.  The inline docs are a little thin on
| examples here.

Oh c'mon we have dozens of examples in the list archives.  So here is another
one -- try with verbose=FALSE to see more:

  R> library(inline) # assume 0.3.10 for rcpp()
  R> inc <- 'const int answer = 42;'
  R> src <- 'Rcpp::Rcout << "The anwer to everything is "
  +                     << answer << std::endl;'
  R> f <- rcpp(signature(), body=src, inc=inc)
  R> f()
  The anwer to everything is 42
  NULL
  R> 

The included segment can have any and all valid code segments: class
definitions, function definitions, other includes, ...

Dirk

-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com  


More information about the Rcpp-devel mailing list