I am wondering if there is an easy way to call the pre-assigned values in r when I wrote cppFunction.
Here is my code:
y=45.3
library(Rcpp)
cppFunction(
"NumericVector demo_fun_cpp(double x) {
NumericVector out1(50);
out1[0] = 2;
for (int i=1; i < 50; ++i) {
out1[i]=x+y+out1[i-1];
}
return out1;
}" )
Error: in sourceCpp(code = code, env = env, rebuild = rebuild, cacheDir = cacheDir, : Error 1 occurred building shared library.
I understand if I assign y
inside of demo_fun_cpp()
function, it will work. However, there are a lot of values that has been assigned in R, so it will be very convenient if I don't have to assign them again.
I am new in C++, I appreciate any help in advance!