[R-pkg-devel] Optional system/C++ library

Dirk Eddelbuettel edd @end|ng |rom deb|@n@org
Tue Mar 30 15:37:01 CEST 2021


On 30 March 2021 at 15:19, Florian Rupprecht wrote:
| I am trying to add an optional system/C++ library to my package and was
| wondering if anyone could point me in the right direction on how to do this
| in the R package ecosystem.
| 
| To be concrete, I want my graphics device package httpgd to be able to call
| into imagemagick/magick++ to add image format support for the various
| formats imagemagick can convert to. For this I need direct C/C++ access as
| the rendering is done in a background thread. Additionally I want to keep
| this completely optional, so httpgd can be compiled and executed when
| imagemagick is not installed on the system.

One uses a file 'configure' to test for properties of the system, and e.g. sets
conditional #define statements for code in src/Makevars, or in src/*h files, or...

This has been done since time immortal using a tool called 'autoconf' which
produces these scripts from input files called 'configure.ac' (or in the case
of very old ones, 'configure.in'). It is very powerful and generic, R itself
uses it.  Many of us have examples across our packages.  An alternative
exists in the outside world with 'cmake', this is used less at CRAN.  Lastly
you can also write 'configure' scripts in sh or R or ...  See 'Writing R
Extensions' for background, and many CRAN packages for examples (which you
can search within the excellent github.org/cran 'org' that mirrors CRAN).

The devil is in the detail of making it robust acrosss platforms and setups.

Dirk

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



More information about the R-package-devel mailing list