Jack Wasey
Jack Wasey

Reputation: 3440

test for whether package is being checked by CRAN

Some functions in my package run much faster using C++11 containers, but CRAN doesn't accept my package using both $(SHLIB_OPENMP_CXXFLAGS) and $(CXX1XSTD) because it doesn't compile on Solaris (or other minor platforms). The recommendation from CRAN was to write a configure script, but I think this will be too time consuming for me to learn, and unnecessarily complicate my code for platforms which few people use.

At the moment, I have just commented out all C++11 code, and removed the $(CXX1XSTD) from Makevars for CRAN submission. This is a poor work around, and I'd much rather be able to detect CRAN in Makevars and make accommodations, so I don't have to maintain a CRAN fork for every version.

I still test whether C++11 is available, but it's just the combination of C++11 and OpenMP flags in Makevars which is the stumbling block on Solaris with CRAN submissions. I feel there must be a trivial way around this.

Is there an environment variable I should use to test whether CRAN itself is checking my package, and which I can test for in Makevars? I have searched the R code base and read R Internals and Writing R Extensions, although I can't say I know them off by heart, which some CRAN maintainers expect. There are environment variables which CRAN likely sets but I expect testing for something like _R_CHECK_CRAN_INCOMING_=TRUE would raise the ire of the maintainers.

I don't think an "if solaris" test in Makevars would be enough: it is the presence of both C++11 and OpenMP flags together which is not allowed, because they would potentially fail on platforms used even less often than Solaris.

Maybe I'm just approaching this the wrong way.

Upvotes: 7

Views: 275

Answers (1)

Jack Wasey
Jack Wasey

Reputation: 3440

Although it may be possible to do a test for this, really the correct way is a configure script. I used configure.ac autoconf to generate it, which wasn't that hard in the end. The C++ code can then use ifdef as needed to test for presence of C++11 symbols, and still use OpenMP #pragma declarations. Windows requires special treatment. I used the method from the RODBC package. This hasn't yet been submitted to CRAN or tested on Solaris, but it does directly answer the CRAN maintainer recommendation.

See: https://github.com/jackwasey/icd

Relevant files are: configure.ac, src/config.h.in, src/Makevars.in

Upvotes: 2

Related Questions