orsos
orsos

Reputation: 43

Rcpp plugin for C++11 not working since update to R 3.4.0

Since I updated R to the new version 3.4.0, the Rcpp plugin to enable C++11 does not seem to work properly. (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 requiring C++11 standard that I compile in R via Rcpp using the command Rcpp::sourceCpp(foo.cpp). The R default standard is C++98 but I could change that by adding the following command in my C++ file
// [[Rcpp::plugins("cpp11")]]

This does not work anymore with the new version of R 3.4.0, my compiler use the default standard (C++98) instead of C++11, despite the plugin. It used to work with previous version of R.

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

Here is the configuration I use 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 use the Rcpp package version 0.12.1.0. My compiler is the following:

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

Am I missing something? Has anyone else encountered the same issue?

Upvotes: 4

Views: 789

Answers (2)

Andrii
Andrii

Reputation: 3043

According Dirk Eddelbuettel answer -- just insert

# 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 !

Upvotes: 1

Dirk is no longer here
Dirk is no longer here

Reputation: 368409

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

So just upgrade to the master branch, or set the env.var manually for now. It is an upstream R change that broke this with no provision for backwards compatibility.

Upvotes: 4

Related Questions