[Rcpp-devel] Idiom for accessing scalars

Steve Lianoglou mailinglist.honeypot at gmail.com
Wed Jan 4 15:44:02 CET 2012


Hi,

2012/1/4 Hadley Wickham <hadley at rice.edu>:
>> We have "as" for this, and wrap for the other way around:
>>
>> f<- cxxfunction(signature(x = "integer"), plugin = "Rcpp", '
>>  int x2 = as<int>(x) ;
>>
>>  return wrap(x2) ;
>> ')
>
> Got it - thanks!
>
> And is there a standard for what you call the C++ equivalent of the R
> arguments?  i.e. x_ = as<int>(x) ?

I don't think there's a "standard" per se, but I actually tend to do
it the other way, ie. put the trailing slash on the incoming SEXP
arguments so that my c(++) code is a bit less tedious:

f<- cxxfunction(signature(x_="integer"), plugin = "Rcpp", '
  int x = as<int>(x_);
  ...
')


-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact


More information about the Rcpp-devel mailing list