[Rd] Detecting compilation under R

From: Barry Rowlingson <b.rowlingson_at_lancaster.ac.uk>
Date: Thu 14 Dec 2006 - 15:14:45 GMT

The docs tell me:

"The header files define USING_R, which should be used to test if the code is indeed being used with R."

but surely you only get that if you #include <R.h>, which you can only do if you are using R. If you have code that you might want to compile in R and for other purposes, how can you detect this?

  As an example, suppose I have some C that uses GSL to get a random number if its a standalone program, or uses R's internals if its being compiled to run in R. I want to do something like:

#ifdef USING_R
#include <R.h>
#include <gsl_random.h>

  and then:

#ifdef USING_R

  x = rand_unif(0.0,1.0);

  x = gsl_runif(0.0,1.0);

  (cant remember the exact names but hopefully you get the idea). This fails because USING_R is only set when R.h is included.

  Are there any preprocessor definitions set by R CMD SHLIB and R CMD BUILD that I can test against?

  Of course I can stick PKG_CFLAGS=-DYES_THIS_IS_USING_R in Makevars, but I just wondered if there was a default solution I'd missed. Or if it was a good idea anyway.


R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri Dec 15 18:03:10 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 15 Dec 2006 - 11:31:00 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.