[R-pkg-devel] compileAttributes() and 'using namespace' directives
Dirk Eddelbuettel
edd at debian.org
Tue Dec 8 15:56:08 CET 2015
Georgi,
Wrong list? Try rcpp-devel for Rcpp question.
On 8 December 2015 at 14:37, Georgi Boshnakov wrote:
| Hi,
|
| With a collaborator we are working on a package which uses Rcpp and RcppArmadillo. Our *.cpp files start with something like
|
| // [[Rcpp::depends(RcppArmadillo)]]
Use that when you use sourceCpp() on a file. In a package, use LinkingTo:.
See the vignette Rcpp Attributes in the Rcpp package.
| #include <iostream>
| #include "RcppArmadillo.h"
|
| using namespace arma;
| using namespace std;
| using namespace Rcpp;
I much prefer explicit namespacing in my package code (as opposed to quick
one-offs). Then again this should not break things.
| Running compileAttributes() generates an RcppExports.cpp which gives errors unless we manually add
|
| using namespace arma;
|
| when everything is fine. Is this outside the scope of the automatic facilities?
|
| compileAttributes() puts the corresponding directive for the Rcpp namespace but even after reading every possible source I could not figure out how to make this happen for the "arma" namespace.
There are over 170 packages on CRAN which use RcppArmadillo. When I am stuck
on problem I often find that compare with that something similar that works
is a good approach.
| The same problem appears when using devtools::test() which exits with an error if RcppExports.cpp is not generated by it but if I remove that file, my understanding is that devtools::test() calls compileAttributes() with the effect of producing invalid file and with little indication for the users what has gone wrong, besides the message "Error: Command failed (1)".
The Rcpp documentation does neither mention nor recommend devtools, so I'd
first try without it. But seems like a side effect of the earlier issue.
Dirk
--
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
More information about the R-package-devel
mailing list