1
votes

I'm trying to use Rcpp on Windows in RStudio. I have R version 3.2.3 and I have installed the Rcpp package. The problem is that I am unable to call any functions defined through the CPP code. I tried the following (picked up from an example online).

body <- '
NumericVector xx(x);
return wrap( std::accumulate( xx.begin(), xx.end(), 0.0));'
add <- cxxfunction(signature(x = "numeric"), body, plugin = "Rcpp")

This gives the following warning, but completes execution successfully.

cygwin warning:
MS-DOS style path detected: C:/R/R-32~1.3/etc/x64/Makeconf
Preferred POSIX equivalent is: /cygdrive/c/R/R-32~1.3/etc/x64/Makeconf
CYGWIN environment variable option "nodosfilewarning" turns off this warning.
Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames

When I try to use the above function,

x <- 1
y <- 2
res <- add(c(x, y))

I get the following error :

R Session Aborted
R encountered a fatal error.
The session was terminated.

Any suggestions? This same 'Fatal Error' happens for any code that I run with Rcpp.

1
Which version of Rtools do you have installed? Which Rcpp version are you using? - Roland
RTools version is 33, Rcpp version is 0.12.2 - yaitzme
My advice is to use Rtools32. Rtools 33 is not stable. - Qiang Kou

1 Answers

1
votes

Try rebuilding locally, starting with Rcpp. This is valid code and will work (and the hundreds of unit tests stress may more than this). Sometimes the compiler or something else changes under you and this sort of thing happens. It is then useful to have an alternative build system -- eg via Travis at GitHub you get Linux for free.

Also, learning about Rcpp Attributes. Your example can be written as

R> library(Rcpp)
R> cppFunction("double adder(std::vector<double> x) { return std::accumulate(x.begin(), x.end(), 0.0); }")
R> adder(c(1,2))
[1] 3
R> 

which is simpler. Works of course the same way with Rcpp::NumericVector.