[R-pkg-devel] Creating a package that links to a 3rd party library: Technical questions

Dirk Eddelbuettel edd @end|ng |rom deb|@n@org
Sat Jul 24 18:35:35 CEST 2021


Russell,

On 24 July 2021 at 12:04, Russell Almond wrote:
| I'm working on a package called RNetica which links to a 3rd party 
| library:  Netica.  Netica is available in both static (libnetica.a) and 
| shared (libnetica.so) version (also Netica.dll for windows, but that is 
| a separate topic).
| 
| I have a version of my package which works very well 
| (github_install("ralmond/RNetica")), but it requires manually moving the 
| `libnetica.so` file into someplace like `/usr/local/lib` where R will 
| find it.
| 
| My preferences for how to deal with this are:
| 
| 1) Figure out a set of flags to send to the linker so that R CMD INSTALL 
| links against the static rather than the dynamic library.
| 
| 2) Figure out how to add a line to the makefile so that `libnetica.so` 
| will be copied to a directory where R will find it.  This is a bit 
| tricky as a user without admin privileges may not have write permission 
| on the proper directory.
| 
| I would be grateful for any suggestions.

Building R packages against third-party C (or C++) packages is a common
topic.  There are a number of subtle sub-points here, and I tried to address
these in a recent-ish paper
   https://arxiv.org/abs/1911.06416
also available as a vignette in the Rcpp package
   http://cran.r-project.org/package=Rcpp/vignettes/Rcpp-libraries.pdf

An actual external (shared or static) library is a pretty tricky step. It has
been done a number of times before, see e.g. our Rblpapi package for use with
the Bloomberg API library ("free as in beer but not in speech" as no source
code) which we download at build time. That is a borderline case, in general
having source is better. Another case is deciding whether to use it as a
system library ("easy", "fast", less compilation; also less "reliable" as you
cannot control but users have) and/or embedding.  The database package span
the gamut there: sometimes the code is embedded, sometimes it is used as a
library on some platforms but locally compiled as part of the package and so
on.

It all depends. You may have a hard case if there are legal / redistribution
issues as per your other email.

Dirk

-- 
https://dirk.eddelbuettel.com | @eddelbuettel | edd using debian.org



More information about the R-package-devel mailing list