[Rd] Detecting compilation under R

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Thu Dec 14 18:57:17 CET 2006


Prof Brian Ripley wrote:

> If *no* R.h is around: easy to solve.

  Have a dummy R.h somewhere?

> What is BUILD?

  Oh, pardon me for forgetting the arbitrary capitalisation of R CMD 
thingies. Can someone come up with a mnemonic for remembering that 
BATCH, COMPILE, SHLIB, INSTALL, LINK and REMOVE are all caps, that 
build, check, and config are lower case, and everything else has initial 
caps? Except for Sd2Rd. (Yes, R --help tells you).

> You've clipped it from my previous mail, with no indication.  As the 
> posting guide points out, this is reprehensible.

  This bit?

#include <R.h>
#ifdef USING_R
x = rand_unif(0.0,1.0);
#else
#include <gsl_random.h>
x = gsl_runif(0.0,1.0);
#endif

  USING_R is only useful here if you can make #include <R.h> not include 
the official R.h file and not give a 'file not found' error message. I 
cant see how to do this without requiring either a dummy R.h file 
somewhere or options on the C command line. This would then be better 
done with cc -DR_CODE and then use #ifdef R_CODE to include R.h. Then 
USING_R is meaningful.

  Here's what I'd like to do. Give someone a file 'simple.c' and say:

  "Compile it with 'cc -o simple simple.c -lgsl' and then run from the 
command line, or do 'R CMD SHLIB simple.c', then do a dyn.load and a 
.C() call'."

  if "R CMD SHLIB" and "R CMD build" set a preprocessor flag then this 
could be done. You could even have -DRSHLIB and -DRbuild on the command 
line to give it a bit more intelligence.

  My behaviour may be reprehensible but sometimes your responses seem 
cryptic to the point of incomprehensible.

Barry



More information about the R-devel mailing list