I want to set -std=c++0x, using Rcpp with inline.
I saw R: C++ Optimization flag when using the inline package but don’t want to make a system-wide change, so I was trying option 2 in Dirk’s answer.
I tried:
settings=getPlugin("Rcpp")
settings$Makevars[length(settings$Makevars)+1] = "CXXFLAGS = $(CXXFLAGS) -std=c++0x"
fun=cxxfunction(signature(x_ ="numeric"),src,plugin="Rcpp",settings=settings,verbose=2);
But the verbose output shows it is ignoring that. I also tried with CFLAGS, and without including existing value, but no effect.
After some source code study, and a hint from Dirk Eddelbuettel, I’ve worked this out:
You can set
PKG_CPPFLAGSthe same way.Here is a complete and more robust example:
The
paste()makes sure if there were any settings already in the plugin then they are preserved.The
unsetenv()is somethingcxxfunctionshould already be doing (IMHO). Currently it will add variables to the environment, but not remove them after. So, without theunsetenv()call, if you later rancxxfunctionagain, but with all defaults, anyCXXFLAGSyou had earlier set would get used. This might not matter, or it might give surprising results. (Imagine if your were usingPKG_CXXFLAGSto set-Wall -Werrorfor your own code, but later code links to a 3rd party library and refuses to compile with those options.)