c++ - Using an integer parameter in Rcpp -


is possible convert integer sexp parameter integer directly without first converting integer vector?

example:

#include <rcpp.h>  sexp f(sexp n) {     rcpp::integervector n_vec(n);     int n1 = n_vec[0];     ...     return r_nilvalue; } 

of course -- as<>() converter this.

it can called explicitly (which need here), called implicitly compiler, or inserted code generation helpers this:

r> cppfunction('int twicethevalue(int a) { return 2*a; }') r> twicethevalue(21) [1] 42 r>  

if call cppfunction() (and related functions rcpp attributes, or inline package) verbose=true argument, see generated code.

here, get

#include <rcpp.h>  rcppexport sexp sourcecpp_47500_twicethevalue(sexp asexp) { begin_rcpp     rcpp::rngscope __rngscope;     int = rcpp::as<int >(asexp);     int __result = twicethevalue(a);     return rcpp::wrap(__result); end_rcpp } 

and our documentation explains begin_rcpp, end_rcpp macros do, why rngscope object there -- , see as<>() , wrap() needed.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -