1#include<Rcpp.h>
2using namespace Rcpp;
3// [[Rcpp::export]]
NumericVector add1(NumericVector x) {
4 NumericVector ans(x.size());
for (int i = 0; i < x.size(); ++i)
ans[i] = x[i] + 1;
return ans;
}
- 1
-
We include the header using
<Rcpp.h>
, not"Rcpp.h"
. - 2
-
This is to avoid typing
Rcpp::
before every object. - 3
- This is a comment that tells Rcpp to export this function to R.
- 4
- Create a vector of the same size as x.