[R] Calling R a la carte?
ross at biostat.ucsf.edu
Thu Dec 9 22:15:49 CET 2004
I have written an R package, mostly implemented in C++. It works.
I want to do unit tests of the C++ code, as well as higher level tests
from R. I use the boost test framework for this, part of which is a
library which wants to be the thing that starts everything running
My code has a few invocations of R functions--just error at the moment,
I think. The list might grow. So I linked the test program with the R
When I first tried this, my test program ended up attempting to start an
R session when I ran it. I switched the order of the R library and the
boost test library, and all worked well (i.e., the boost test framework
got control, ran all the tests, and all passed).
That was on Linux. I am now porting to Mac OS X, and am back to having
R start in place of my test suite (it only tries to start, because it
runs into problems).
Really I just want a little bit of R (hence the subject: R a la carte).
The extensions document only talks about embedding a complete R session
in another program, and the same is true on previous posts I've found on
1) Is this a good idea? On reflection, if the error() function is ever
called it may require a context, and there will be none. More
generally, I'm doing nothing to setup R (beyond setting environment
variables), and the library may just not be designed for that kind of
use. Also, the test framework can cope with tests segfaulting.
2) Why is the R library taking control of my startup? The extensions
document seems to imply that if I'm using the library I must
deliberately invoke functions from my main() to get R running. I don't,
but it still runs.
3) What would be the best way to accomplish my goal? I can think of
a) basically continue with what I'm doing. This obviously would
require some work around to the start up issues. My test suite doesn't
hit any code that actually calls the R functions.
b) Treat R as a real embedded application, setting it up correctly.
I'm not sure if it is possible to do this while also triggering the test
suite. In other words, the sequence would need to be
initialize test framework
start up R session
The R session does not invoke the tests.
c) Write a small library that fakes the R routines I need, and link
to it when testing.
P.S. I originally saw this with R 1.9 on Linux, since upgraded to 2.0.
On the Mac, it's 1.9.
Ross Boylan wk: (415) 502-4031
530 Parnassus Avenue (Library) rm 115-4 ross at biostat.ucsf.edu
Dept of Epidemiology and Biostatistics fax: (415) 476-9856
University of California, San Francisco
San Francisco, CA 94143-0840 hm: (415) 550-1062
More information about the R-help