Skip to content
Prev 273601 / 398506 Next

Problem with .C

An obvious reason might be that your second argument should be a  
pointer to int.

As others have mentioned, you might want to have a look at Rccp and/or  
inline. The documentation is good and I find it much easier to work  
with.

For example, your example could be written as:

library(Rcpp)
library(inline)

test <- cxxfunction(signature(x = "numeric" ) , '
     Rcpp::NumericVector v(x);
     Rcpp::NumericVector result(v.length());
     for (int i = 0; i < v.length(); ++i) {
         result[i] = v[i] + i;
     }
     return(result);
     ', plugin = "Rcpp" )


HTH,

Jan


Quoting Grigory Alexandrovich <alexandrovich at mathematik.uni-marburg.de>: