Hi, I've started using Rcpp recently and it's great! Is there a list of which of the Makevars variables are evaluated, i.e., ones that I can declare as backticks for conditional results. For example, I'd like to be able to declare an environment variable during package installation, e.g.: USE_OPENCL=yes R CMD INSTALL package but neither PKG_CPPFLAGS += `if ! [ -z $(USE_OPENCL) ]; then echo '-DUSE_OPENCL'; fi` nor PKG_CXXFLAGS += `if ! [ -z $(USE_OPENCL) ]; then echo '-DUSE_OPENCL'; fi` seems to work. Thanks, Gad -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20131001/690e86d3/attachment.html>
[Rcpp-devel] Makevars flags that get evaluated
4 messages · Gad Abraham, Dirk Eddelbuettel, John Chambers
On 1 October 2013 at 22:37, Gad Abraham wrote:
| Hi, | | I've started using Rcpp recently and it's great! Cool! | Is there a list of which of the Makevars variables are evaluated, i.e., ones | that I can declare as backticks for conditional results. For example, I'd like | to be able to declare an environment variable during package installation, | e.g.: | | USE_OPENCL=yes R CMD INSTALL package | | | but neither | PKG_CPPFLAGS += `if ! [ -z $(USE_OPENCL) ]; then echo '-DUSE_OPENCL'; fi` | nor | PKG_CXXFLAGS += `if ! [ -z $(USE_OPENCL) ]; then echo '-DUSE_OPENCL'; fi` | | seems to work. That seems a little fragile. I would try this in src/Makevars, which use the Make language (which also inherits environment variables as I dimly recall) but can also execute shell snippets. Or you try to set up a local plugin for use by Rcpp Attributes. Then you get a hook into R code where you can query the (shell) environment variables and act accordingly. We now have plugins for c++11 -- and as of the Rcpp 0.10.5 release from this weekend also for openmp. Dirk
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
On 1 October 2013 at 09:02, Dirk Eddelbuettel wrote:
| On 1 October 2013 at 22:37, Gad Abraham wrote:
| | Is there a list of which of the Makevars variables are evaluated, i.e., ones | | that I can declare as backticks for conditional results. For example, I'd like | | to be able to declare an environment variable during package installation, | | e.g.: | | | | USE_OPENCL=yes R CMD INSTALL package | | | | | | but neither | | PKG_CPPFLAGS += `if ! [ -z $(USE_OPENCL) ]; then echo '-DUSE_OPENCL'; fi` | | nor | | PKG_CXXFLAGS += `if ! [ -z $(USE_OPENCL) ]; then echo '-DUSE_OPENCL'; fi` | | | | seems to work. | | That seems a little fragile. I would try this in src/Makevars, which use the | Make language (which also inherits environment variables as I dimly recall) | but can also execute shell snippets. Upon a second look, I suspect all you really want is to prefix 'R CMD INSTAL ...' with a direct argument to, say, PKG_CXXFLAGS. Here is a quick example from one of my smaller packages: edd at max:~/svn/rcpp/pkg$ R CMD INSTALL RcppXts_0.0.4.1.tar.gz * installing to library ?/usr/local/lib/R/site-library? * installing *source* package ?RcppXts? ... ** libs ccache g++-4.7 -I/usr/share/R/include -DNDEBUG -I"/usr/local/lib/R/site-library/Rcpp/include" -I"/usr/local/lib/R/site-library/xts/include" -fpic -g -O3 -Wall -pipe -Wno-unused -pedantic -c xtsMod.cpp -o xtsMod.o g++-4.7 -shared -o RcppXts.so xtsMod.o -L/usr/local/lib/R/site-library/Rcpp/lib -lRcpp -Wl,-rpath,/usr/local/lib/R/site-library/Rcpp/lib -L/usr/lib/R/lib -lR installing to /usr/local/lib/R/site-library/RcppXts/libs ** R ** inst ** preparing package for lazy loading ** help *** installing help indices ** building package indices ** testing if installed package can be loaded * DONE (RcppXts) edd at max:~/svn/rcpp/pkg$ PKG_CXXFLAGS=-DUSE_OPENCL R CMD INSTALL RcppXts_0.0.4.1.tar.gz * installing to library ?/usr/local/lib/R/site-library? * installing *source* package ?RcppXts? ... ** libs ccache g++-4.7 -I/usr/share/R/include -DNDEBUG -I"/usr/local/lib/R/site-library/Rcpp/include" -I"/usr/local/lib/R/site-library/xts/include" -DUSE_OPENCL -fpic -g -O3 -Wall -pipe -Wno-unused -pedantic -c xtsMod.cpp -o xtsMod.o g++-4.7 -shared -o RcppXts.so xtsMod.o -L/usr/local/lib/R/site-library/Rcpp/lib -lRcpp -Wl,-rpath,/usr/local/lib/R/site-library/Rcpp/lib -L/usr/lib/R/lib -lR installing to /usr/local/lib/R/site-library/RcppXts/libs ** R ** inst ** preparing package for lazy loading ** help *** installing help indices ** building package indices ** testing if installed package can be loaded * DONE (RcppXts) edd at max:~/svn/rcpp/pkg$ See how the -DUSE_OPENCL carries through? (It doesn't do anything for my package, but your get the idea.) R even strips quotes, so you can also say $ PKG_CXXFLAGS="-DUSE_OPENCL" R CMD INSTALL instead of $ PKG_CXXFLAGS=-DUSE_OPENCL R CMD INSTALL You can glance at the file $(R_HOME)/etc/Makeconf to see the other PKG_* variables. Hth, Dirk
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
7 days later
The function exposeClass() has been added to Rcpp. The idea is to call it to create C++ and R files in a package source in order to export a C++ class, given basic information about the class.
The function writes the Module source in C++ and a corresponding call to setRcppClass in R.
Like compileAttributes(), it would be called with the working directory set to the top source directory of a package. It doesn't do any parsing, so needs more information than compileAttributes().
For direct fields and methods, just the names. For constructors and inherited fields and methods, type information as well. Optional arguments allow for read-only fields and renaming of members.
The function has also been added to the master git source for Rcpp11.
The example from the documentation is included below.
John
---------------
### Given the following C++ class, defined in file PopBD.h,
### the call to exposeClass() shown below will write a file
### src/PopBDModule.cpp containing a corresponding module definition.
### class PopBD {
### public:
### PopBD(void);
### PopBD(NumericVector initBirth, NumericVector initDeath);
###
### std::vector<double> birth;
### std::vector<double> death;
### std::vector<int> lineage;
### std::vector<long> size;
### void evolve(int);
###
### };
### A file R/PopBDClass.R will be written containing the one line:
### PopBD <- setRcppClass("PopBD")
###
### The call below exposes the lineage and size fields, read-only,
### and the evolve() method.
exposeClass("PopBD",
constructors =
list("", c("NumericVector", "NumericVector")),
fields = c("lineage", "size"),
methods = "evolve",
header = '#include "PopBD.h"',
readOnly = c("lineage", "size"))
### Example with inheritance: the class PopCount inherits from
### the previous class, and adds a method table(). It has the same
### constructors as the previous class.
### To expose the table() method, and the inherited evolve() method and size field:
exposeClass("PopCount",
constructors =
list("", c("NumericVector", "NumericVector")),
fields = c(size = "std::vector<long>"),
methods = list("table", evolve = c("void", "int")),
header = '#include "PopCount.h"',
readOnly = "size")
}