Rikard N Rikard N - 6 months ago 35
R Question

How to create CRAN ready R package that have external dependencies (libxml2)

I have created an R package that I would like to submit to CRAN. It contains code that needs to be compiled (plain C) and this code depends on the

library. My current solution is to let Linux and Mac users install the
package, which lets them compile and install the R source package. For Windows I have created a special binary R-package that contains the needed binary dependencies. When reading the CRAN guidelines I see that only source packages may be uploaded and that they may not contain any binary files.

My questions are then:

  1. Is it ok for Mac/Linux to have the user install libxml2-dev prior to installing the R package or are there alternative solutions?

  2. How should I do for Windows where the libxml2 is not straight forward to install for an end user?


As mentioned above, you can just copy over what the xml2 package does:

  • To get things to work on Linux/MacOS, copy the files configure and /src/Makevars.in. Note that macOS includes a copy of libxml2 by default, so you can safely link to -lxml2 as you would do on Linux.

  • For Windows need to copy the files src/Makevars.win and tools/winlibs.R from xml2. This is a simple script that automatically downloads and statically links libxml2 from rwinlib when building the R package on Windows.

These build scripts are tested to work on (almost) any platform.