Hi, when I put // [[Rcpp::depends(...)]] inside an #ifdef, Rcpp "sees" this attribute and attempts to load the package even when the condition is false. Is there a way to make the Rcpp::depends attribute conditional?
I tried putting the attribute in a separate .h file and conditionally #include-ing that file, but that has exactly the same issue -- Rcpp "sees" the #include and always follows it regardless of the enclosing #ifdef.
My use case is that I have a .cpp file (for use with sourceCpp) with an optional dependency on some package "foo". I'd like to let users enable the use of foo by setting PKG_CPPFLAGS=-DFOO. I can wrap the C++ code that uses foo in an #ifdef FOO, but that doesn't work for the Rcpp::depends attribute (which is always "seen" by Rcpp and causes an error if foo is not installed).
The best workaround I can think of is to read the .cpp file, conditionally delete the #ifdef FOO ... #endif, and pass the result to sourceCpp(code=...). I'd appreciate any better ideas.
I think the proper solution is for Rcpp to run the real C preprocessor instead of trying to emulate it, but I'm not sure how difficult that would be. At the very least it would be nice if the current behaviour was documented, because the inconsistency with the real C preprocessor is surprising (#include is respected, but #ifdef etc. are not).
Hi, when I put
// [[Rcpp::depends(...)]]inside an#ifdef, Rcpp "sees" this attribute and attempts to load the package even when the condition is false. Is there a way to make the Rcpp::depends attribute conditional?I tried putting the attribute in a separate .h file and conditionally #include-ing that file, but that has exactly the same issue -- Rcpp "sees" the
#includeand always follows it regardless of the enclosing#ifdef.My use case is that I have a .cpp file (for use with
sourceCpp) with an optional dependency on some package "foo". I'd like to let users enable the use of foo by settingPKG_CPPFLAGS=-DFOO. I can wrap the C++ code that uses foo in an#ifdef FOO, but that doesn't work for the Rcpp::depends attribute (which is always "seen" by Rcpp and causes an error if foo is not installed).The best workaround I can think of is to read the .cpp file, conditionally delete the
#ifdef FOO ... #endif, and pass the result tosourceCpp(code=...). I'd appreciate any better ideas.I think the proper solution is for Rcpp to run the real C preprocessor instead of trying to emulate it, but I'm not sure how difficult that would be. At the very least it would be nice if the current behaviour was documented, because the inconsistency with the real C preprocessor is surprising (
#includeis respected, but#ifdefetc. are not).