Download citation...
Asked 6th Sep, 2014
Deleted profile

Can anyone help me with this problem when running R scripts from C/C++?

I am working on a C++ program that depends on an R package, using Rcpp and RInside to bridge the gap. While I can execute as many lines of R as I like by calling RInside::parseEvalQ() for each line, it would be more readable and more maintainable to put the R portion of the program in a .r script. Unfortunately, I can't quite get it to work.
The naive approach, calling parseEvalQ("source('foo.r')"), looks for a file foo.r located in the program's working directory, rather than the source or installation directory. This can lead to highly unpredictable behavior, depending on where the program is being called from. The only alternative I've been able to find is to give a hardcoded path to the file, which is a portability nightmare.
Does anyone know of a way to ensure that either
  • the embedded R session searches for files relative to the C++ executable it's embedded in, or
  • the compiler and/or preprocessor somehow accounts for the contents of a specific .r file during building?
Either approach would solve my problem.
11th Sep, 2014
M. O. Vasil’ev
May be you may use autotools to generate config.h for you and make it generate some variable like installpath or so?