0

I'm looking over the demo provided in 3.6 of the Rcpp-FAQ, and I'm trying to understanding how this plugin is being created. The standalone example provided is

gslrng <-
'int seed = Rcpp::as<int>(par) ;
gsl_rng_env_setup();
gsl_rng *r = gsl_rng_alloc (gsl_rng_default);
gsl_rng_set (r, (unsigned long) seed);
double v = gsl_rng_get (r);
gsl_rng_free(r);return Rcpp::wrap(v);'

plug <- Rcpp:::Rcpp.plugin.maker(
  include.before = "#include <gsl/gsl_rng.h>",
  libs = paste("-L/usr/local/lib/R/site-library/Rcpp/lib -lRcpp",
               "-Wl,-rpath,/usr/local/lib/R/site-library/Rcpp/lib",
               "-L/usr/lib -lgsl -lgslcblas -lm"))
registerPlugin("gslDemo", plug )
fun <- cxxfunction(signature(par="numeric"), gslrng, plugin="gslDemo")
fun(0)

Specifically, why is that call to paste() being comma-separated like that? Should all dependencies (header file directories, linker directories, and name of library files) be handled via plugins?

Taylor
  • 1,797
  • 4
  • 26
  • 51
  • 1
    Is this a followup question to [my previous answer](https://stackoverflow.com/a/54168141/8416610)? In that case it might make sense if you tell us what you are trying to achieve. The question about `paste` is basic R, while the second question is quite vague. – Ralf Stubner Jul 04 '19 at 09:35
  • @RalfStubner It is indeed! (thank you for your help). My ultimate goal is to help c++-averse statisticians use a [c++ library I wrote](https://github.com/tbrown122387/pf). I get paste, it was the [commas](https://stackoverflow.com/questions/6562403/i-dont-understand-wl-rpath-wl) that was throwing me. – Taylor Jul 04 '19 at 13:40
  • Ok. Now I understand which commas you mean. I have not looked closely at your library, but would it be necessary for the user to write C++ code or can all the functionality of the library exposed as R functions? In the latter case you would not need a Rcpp plugin. Just include the library in the R package and use Rcpp to interface between R and the library. – Ralf Stubner Jul 04 '19 at 14:24
  • @RalfStubner unfortunately they would need to write a c++ header for every model/filter pair (something like [this](https://github.com/tbrown122387/pf/blob/master/examples/svol_bs.h) Compilation needs to be re-done every time you change the model or inherit from a different filter. – Taylor Jul 04 '19 at 15:08
  • Can you make the library header-only like RcppEigen or RcppAramdillo? That would simplify things a lot. – Ralf Stubner Jul 04 '19 at 15:20

1 Answers1

2

The paste() is a vanilla use of base R's paste() -- it creates a single string containing all the link instructions being passed to libs.

For include.before we do not need that as only one header is passed.

I would recommend you study the code along with its use as well as the actual plugin for RcppGSL which is defined here and see how they are used in packages such as e.g. RcppZiggurat. And by used I mean see what the instructions expand to when the client packages compiles and links.

It looks crazy complicated but hey it has worked for about a decade already :)

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725