From b.rowlingson at lancaster.ac.uk  Thu Dec 14 18:57:17 2006
From: b.rowlingson at lancaster.ac.uk (Barry Rowlingson)
Date: Thu, 14 Dec 2006 17:57:17 +0000
Subject: [Rd] Detecting compilation under R
In-Reply-To: <Pine.LNX.4.64.0612141716400.3286@gannet.stats.ox.ac.uk>
References: <45816A65.8000802@lancaster.ac.uk>
	<Pine.LNX.4.64.0612141618580.29210@gannet.stats.ox.ac.uk>
	<45818652.7050102@lancaster.ac.uk>
	<Pine.LNX.4.64.0612141716400.3286@gannet.stats.ox.ac.uk>
Message-ID: <4581907D.10500@lancaster.ac.uk>

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



[Rd] Detecting compilation under R
Barry Rowlingson