Le 04/01/12 14:29, Hadley Wickham a écrit :
Hi all,

I'm still just getting my feet wet in Rcpp, so please excuse the
naivety of my question, but is this the appropriate idiom for treating
an input as a C++ scalar?

f<- cxxfunction(signature(x = "integer"), plugin = "Rcpp", '
   Rcpp::IntegerVector x1(x);
   int x2 = x1[0];

   return(Rcpp::NumericVector(x2));
')

i.e. is there any way I can turn x in x2 more succinctly?  (This
function is just for illustrative purposes - I'm trying to do
something at least a little more complicated)

Thanks!

Hadley
Yep,

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) ;
')


Romain
--
Romain Francois
Professional R Enthusiast
http://romainfrancois.blog.free.fr

_______________________________________________
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