Ramiro Magno
Ramiro Magno

Reputation: 3175

How does R check for system external dependencies when installing an R package?

For instance, while trying to install the R package curl as a dependency of usethis:

* installing *source* package ‘curl’ ...
** package ‘curl’ successfully unpacked and MD5 sums checked
Package libcurl was not found in the pkg-config search path.
Perhaps you should add the directory containing `libcurl.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libcurl' found
Package libcurl was not found in the pkg-config search path.
Perhaps you should add the directory containing `libcurl.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libcurl' found
Using PKG_CFLAGS=
Using PKG_LIBS=-lcurl
------------------------- ANTICONF ERROR ---------------------------
Configuration failed because libcurl was not found. Try installing:
 * deb: libcurl4-openssl-dev (Debian, Ubuntu, etc)
 * rpm: libcurl-devel (Fedora, CentOS, RHEL)
 * csw: libcurl_dev (Solaris)
If libcurl is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a libcurl.pc file. If pkg-config
is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:
R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'

R detects that I don't have libcurl installed. At what level is this external dep. specified? I know that external dependencies can be indicated in the DESCRIPTION file, and indeed curl's pkg DESCRIPTION file does contain:

SystemRequirements: libcurl: libcurl-devel (rpm) or libcurl4-openssl-dev (deb).

But is that line what allowed R to detect the missing dependency and print that error? Can't be, right? How could it? So, how is R doing it?

Upvotes: 7

Views: 637

Answers (1)

Dirk is no longer here
Dirk is no longer here

Reputation: 368271

Briefly:

  1. This is all in Writing R Extension.
  2. In short, it doesn't i.e. R does not help you. See below.
  3. CRAN (and Bioconductor) package dependencies can be declared.
  4. For everything else you can only approximate via SystemRequirements in DESCRIPTION
  5. This is not a solved or solvable problem of all depends across all operating systems
  6. So no other language has it either.
  7. What one can get is a package manager in a 'vertical' stack -- say brew or apt. That is pretty good, but it also does not work at the CRAN source level.
  8. So all one can do is, as you show, invoke something executable called configure to test if resources are present, and to abort with clear errors if not.
  9. For the package you show, that test code in configure is here.
  10. There is a sibbling Windows version too.

Upvotes: 10

Related Questions