1

I'm doing some work in R that depends on the package ldatuning. I got the package set up and a script running on my local windows machine. It looks like it will take awhile to run, so I spun up a Linux VM (Ubuntu 16.06) in the cloud to run the script. I tried to set up the environment in R with install.packages('ldatuning'), but had a lot of errors. After some digging, I realized that some of the R packages that ldatuning depends on also had dependencies on Linux libraries. In fact there were three different packages that depended on a Linux library. I had to search on stack overflow in each case, and always found brief answers like this one or this one. So how did the people that answered those questions know which libraries to install? I understand that often there are R packages that depend directly on Linux libraries, but how could I know the exact Linux libraries I would need ahead of time? For example, for the R library gmp, my guess would be to try sudo apt-get install gmp, but that doesn't work - it is sudo apt-get install libgmp3-dev. How could I find out that the R package gmp depends on libgmp3-dev?

Amadou Kone
  • 907
  • 11
  • 21

1 Answers1

4

Unfortunately there's not yet a great, complete, and uniform way to deal with this. A great project toward that end is https://github.com/r-hub/sysreqsdb, which you should definitely check out, and may help you.

Also, often when you have an error installing a package due to an unmet system dependency, part of the installation output will tell you how to solve the problem; for example, here's part of the output from a failed installation of pdftools:

No package 'poppler-cpp' found
Using PKG_CFLAGS=-I/usr/include/poppler/cpp -I/usr/include/poppler
Using PKG_LIBS=-lpoppler-cpp
------------------------- ANTICONF ERROR ---------------------------
Configuration failed because poppler-cpp was not found. Try installing:
 * deb: libpoppler-cpp-dev (Debian, Ubuntu, etc)
 * rpm: poppler-cpp-devel (Fedora, CentOS, RHEL)
 * csw: poppler_dev (Solaris)
 * brew: poppler (Mac OSX)
If poppler-cpp is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a poppler-cpp.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=...'
--------------------------------------------------------------------
ERROR: configuration failed for package ‘pdftools’
* removing ‘/home/duckmayr/R/x86_64-pc-linux-gnu-library/3.5/pdftools’

However, there's still some cases where those things will not resolve your issue. I would always check the package's DESCRIPTION and/or website -- they often mention system dependencies somewhere there, and also often mention where you can get the dependency, but not always. For the remaining cases, you just have to hope to be lucky Googling your problem.

Example: pdftools

The pdftools CRAN page (which I reached by Googling "r pdftools") displays information from its DESCRIPTION, including

SystemRequirements: Poppler C++ API: libpoppler-cpp-dev (deb) or poppler-cpp-devel (rpm). The unit tests also require the 'poppler-data' package (rpm/deb)

So, even if they didn't have that informative message above, I could have found it that way.

Example: ldatuning

If you look at the ldatuning CRAN page, you'll see no such entry. That's because it doesn't have any system dependencies -- its R package dependencies do. In such a case, you'd look to see which package installation failed (by looking through the output after install.packages("ldatuning") to see that (as it sounds like happened in your case), installation of Rmpfr failed.

So, just head on over to the Rmpfr CRAN page to see

SystemRequirements: gmp (>= 4.2.3), mpfr (>= 3.0.0)

which is more helpful, but not quite as helpful as the pdftools example. However, it also lists

URL: http://rmpfr.r-forge.r-project.org/

Then, on that page, we see

Installation from source: Needs MPFR and GMP libraries either from the above web pages, or much more conveniently from your Linux distribution package system:

Debian, Ubuntu, etc . . . . . . . .: sudo apt-get install libmpfr-dev
Fedora, Redhat, CentOS, (open)SuSE: sudo dnf install mpfr-devel

which should get you sorted.

duckmayr
  • 16,303
  • 3
  • 35
  • 53