Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make missing packages error message more detailed #284

Open
florian-speer opened this issue Jun 24, 2024 · 1 comment
Open

Make missing packages error message more detailed #284

florian-speer opened this issue Jun 24, 2024 · 1 comment

Comments

@florian-speer
Copy link

When the dependencies of a package are loaded via load_all() (e.g. during devtools::test()) and some libraries could not be loaded, the reason for the failure is not included in the error message. Loading the dependency directly with library() provides information about the reason, at least in the case of a missing Linux system library. It would be great if the error message "The packages [...] are required." also included the reason(s).

Dockerfile to reproduce:

FROM rocker/tidyverse

RUN git clone https://github.com/ropensci/rnaturalearth.git

WORKDIR /rnaturalearth/

RUN Rscript -e 'devtools::install_deps()'
RUN Rscript -e 'devtools::test()' || true
RUN Rscript -e 'pkgload::load_all()' || true
RUN Rscript -e 'library(sf)' || true
RUN Rscript -e 'library(terra)' || true

Output from image build:

Step 1/8 : FROM rocker/tidyverse
 ---> 0ec3740b9fe5
Step 2/8 : RUN git clone https://github.com/ropensci/rnaturalearth.git
 ---> Running in 400126c8ecb7
Cloning into 'rnaturalearth'...
Removing intermediate container 400126c8ecb7
 ---> bfbe32b7e4cf
Step 3/8 : WORKDIR /rnaturalearth/
 ---> Running in 8eb43ddb24d6
Removing intermediate container 8eb43ddb24d6
 ---> f32753059a23
Step 4/8 : RUN Rscript -e 'devtools::install_deps()'
 ---> Running in a4e752ccd104
wk       (NA    -> 0.9.1 ) [CRAN]
proxy    (NA    -> 0.4-27) [CRAN]
e1071    (NA    -> 1.7-14) [CRAN]
units    (NA    -> 0.8-5 ) [CRAN]
s2       (NA    -> 1.1.6 ) [CRAN]
DBI      (1.2.1 -> 1.2.3 ) [CRAN]
classInt (NA    -> 0.4-10) [CRAN]
openssl  (2.1.1 -> 2.2.0 ) [CRAN]
curl     (5.2.0 -> 5.2.1 ) [CRAN]
terra    (NA    -> 1.7-78) [CRAN]
sf       (NA    -> 1.0-16) [CRAN]
Installing 11 packages: wk, proxy, e1071, units, s2, DBI, classInt, openssl, curl, terra, sf
Installing packages into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
trying URL 'https://p3m.dev/cran/__linux__/jammy/latest/src/contrib/wk_0.9.1.tar.gz'
Content type 'binary/octet-stream' length 1720628 bytes (1.6 MB)
==================================================
downloaded 1.6 MB

[... shortened for conciseness ...}

trying URL 'https://p3m.dev/cran/__linux__/jammy/latest/src/contrib/sf_1.0-16.tar.gz'
Content type 'binary/octet-stream' length 3557771 bytes (3.4 MB)
==================================================
downloaded 3.4 MB

* installing *binary* package ‘wk’ ...
* DONE (wk)
* installing *binary* package ‘proxy’ ...
* DONE (proxy)
* installing *binary* package ‘units’ ...
* DONE (units)
* installing *binary* package ‘DBI’ ...
* DONE (DBI)
* installing *binary* package ‘openssl’ ...
* DONE (openssl)
* installing *binary* package ‘curl’ ...
* DONE (curl)
* installing *binary* package ‘terra’ ...
* DONE (terra)
* installing *binary* package ‘e1071’ ...
* DONE (e1071)
* installing *binary* package ‘s2’ ...
* DONE (s2)
* installing *binary* package ‘classInt’ ...
* DONE (classInt)
* installing *binary* package ‘sf’ ...
* DONE (sf)

The downloaded source packages are in
        ‘/tmp/RtmphDC25v/downloaded_packages’
Removing intermediate container a4e752ccd104
 ---> 402ab30af47e
Step 5/8 : RUN Rscript -e 'devtools::test()' || true
 ---> Running in 2e9a136e0054
ℹ Testing rnaturalearth
Error in load_imports(path) : 
  The packages "sf" (>= 0.3-4) and "terra" are required.
Calls: <Anonymous> ... load_imports -> deps_check_installed -> check_installed
Execution halted
Removing intermediate container 2e9a136e0054
 ---> 520a20906c8a
Step 6/8 : RUN Rscript -e 'pkgload::load_all()' || true
 ---> Running in fc6c321baa5d
ℹ Loading rnaturalearth
Error in load_imports(path) : 
  The packages "sf" (>= 0.3-4) and "terra" are required.
Calls: <Anonymous> ... load_imports -> deps_check_installed -> check_installed
Execution halted
Removing intermediate container fc6c321baa5d
 ---> 3c8ca603248d
Step 7/8 : RUN Rscript -e 'library(sf)' || true
 ---> Running in e14cab3a5ba9
Error: package or namespace load failed for ‘sf’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/usr/local/lib/R/site-library/units/libs/units.so':
  libudunits2.so.0: cannot open shared object file: No such file or directory
Execution halted
Removing intermediate container e14cab3a5ba9
 ---> 1759af5b290c
Step 8/8 : RUN Rscript -e 'library(terra)' || true
 ---> Running in 6a78a00da5cd
Error: package or namespace load failed for ‘terra’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/usr/local/lib/R/site-library/terra/libs/terra.so':
  libproj.so.22: cannot open shared object file: No such file or directory
Execution halted
Removing intermediate container 6a78a00da5cd
 ---> 6789a4ee769f

Expected behavior:
The error messages that are thrown for devtools::test() and pkgload::load_all() contain the information that the sf and terra packages can't be loaded because the system libraries libudunits2 and libproj are missing, similar to the error messages thrown for library(sf) and library(terra)

@olivroy
Copy link
Contributor

olivroy commented Jun 28, 2024

You may want to replace

RUN Rscript -e 'devtools::install_deps()'

with

RUN Rscript -e 'pak::local_install_deps()'

or pak::local_install_dev_deps()

pak errors when it can't install a dependency

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants