Rcpp plugin for C ++ 11 does not work since upgrade to R 3.4.0

Since I updated R to the newer version 3.4.0, the Rcpp plugin to include C ++ 11 doesn't seem to work as expected. (Note that this is a different situation as reported here http://r.789695.n4.nabble.com/R-3-4-has-broken-C-11-support-td4732692.html )

I have C ++ files that require the C ++ 11 standard, which I compile to R via Rcpp using the command Rcpp::sourceCpp(foo.cpp)

. The default R standard is C ++ 98, but I could change that by adding the following command to my C ++ file
// [[Rcpp::plugins("cpp11")]]

This doesn't work anymore with the new R 3.4.0, my compiler is using the default standard (C ++ 98) instead of C ++ 11, despite the plugin. It worked with the previous version of R.

My solution at the moment is to set an environment variable for my R session: Sys.setenv("PKG_CXXFLAGS"="-std=c++11")

Here's the configuration I'm using in R:

sessionInfo()
R version 3.4.0 (2017-04-21) Platform: x86_64-suse-linux-gnu (64-bit) Running under: openSUSE Leap 42.2
Matrix products: default BLAS: /usr/lib64/R/lib/libRblas.so LAPACK: /usr/lib64/R/lib/libRlapack.so locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages: [1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached): [1] compiler_3.4.0 rsconnect_0.4.3 tools_3.4.0


I am using Rcpp version 0.12.1.0. My compiler is as follows:

~$ g++ --version | head -n1
g++ (SUSE Linux) 4.8.5 
      

Am I missing something? Has anyone else faced the same problem?

+3


source to share


2 answers


This was reported yesterday in the GitHub issue tracker at # 683 and has already been closed in a pull request # 684 which is now merged.



So, just update the master branch or manually set env.var. This is an upstream change to R that broke this by not allowing for backward compatibility.

+4


source


In response to Dirk Eddelbuettel's answer - just paste

# R code
Sys.setenv("USE_CXX11" = "yes")
sourceCpp("code.cpp")

# C++ code
// [[Rcpp::plugins(cpp11)]]
// [[Rcpp::export]]                                                                       
double myhypot(double x, double y) {
return std::hypot(x,y);

      



}

... and it really works!

0


source







All Articles