#includeusing namespace Rcpp; // [[Rcpp::export]] int getSize(IntegerVector x) { int size = x.size(); return size; } /*** R getSize(c(1, 2, 3)) */
#includeThis example shows a function that takes a NumericVector as input, calculates its size, and performs an operation on each element to create a new NumericVector. Package library: Rcpp.using namespace Rcpp; // [[Rcpp::export]] NumericVector myFun(NumericVector x) { int N = x.size(); NumericVector y(N); for (int i = 0; i < N; i++){ y[i] = x[i] * x[i]; } return y; } /*** R myFun(c(1, 2, 3)) */