I'm rebuilding a custom R package which has, among other libraries, RcppArmadillo in the Depends row of the DESCRIPTION file.
I am running R 3.5.1. When I rebuild the package in RStudio, I get an error:
ERROR: dependency ‘RcppArmadillo’ is not available for package 'custom package name'
According to the R Packages book, packages under Depends/Imports must be installed when the package is rebuilt.
Use devtools::install()
instead.
According the RStudio website,
The Build and Reload command performs several steps in sequence to ensure a clean and correct result:
1.Unloads any existing version of the package (including shared libraries ifnecessary).
2.Builds and installs the package using R CMD INSTALL.
3.Restarts the underlying R session to ensure a clean environment for re-loading the package.
4.Reloads the package in the new R session by executing the library function.
While devtools::install()
will install dependencies for you -- from help("install.packages")
:
Uses R CMD INSTALL to install the package. Will also try to install dependencies of the package from CRAN, if they're not already installed.
(emphasis added) this is not the case for R CMD INSTALL
alone (see ?INSTALL
from R or R CMD INSTALL --help
from the command line, etc. -- there is no mention of installing required dependencies).
So, it appears the language
In fact, any time your package is installed, those packages will, if not already present, be installed on your computer (devtools::load_all() also checks that the packages are installed).
from Hadley's R Packages is a little specific; it does not pertain to using R CMD INSTALL
(which RStudio's build function apparently uses), but does work for devtools::install()
. It's a matter of personal taste, but honestly I highly recommend using devtools
in your package development workflow.
I removed the package rbenchmark
from my system via
remove.packages("rbenchmark")
then created a dummy package by
devtools::create("SOexample", rstudio = FALSE)
and edited the DESCRIPTION to put rbenchmark
in Imports, so that SOexample
depends on it. I added the following code in R/hello_world.R
:
hello_world <- function() print("Hello, world!")
I tried R CMD INSTALL
, but got the error
*installing to library ‘/home/duckmayr/R/x86_64-pc-linux-gnu-library/3.5’
ERROR: dependency ‘rbenchmark’ is not available for package ‘SOexample’
*removing ‘/home/duckmayr/R/x86_64-pc-linux-gnu-library/3.5/SOexample’
But, if I try devtools::install()
:
> devtools::install("SOexample/")
Installing SOexample
trying URL 'https://cloud.r-project.org/src/contrib/rbenchmark_1.0.0.tar.gz'
Content type 'application/x-gzip' length 5093 bytes
==================================================
downloaded 5093 bytes
Installing rbenchmark
'/usr/lib/R/bin/R' --no-site-file --no-environ --no-save --no-restore --quiet \
CMD INSTALL '/tmp/RtmpA0NOMe/devtools723832018149/rbenchmark' \
--library='/home/duckmayr/R/x86_64-pc-linux-gnu-library/3.5' --install-tests
* installing *source* package ‘rbenchmark’ ...
** package ‘rbenchmark’ successfully unpacked and MD5 sums checked
** R
** demo
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (rbenchmark)
'/usr/lib/R/bin/R' --no-site-file --no-environ --no-save --no-restore --quiet \
CMD INSTALL '/home/duckmayr/SOexample' \
--library='/home/duckmayr/R/x86_64-pc-linux-gnu-library/3.5' --install-tests
* installing *source* package ‘SOexample’ ...
** R
** byte-compile and prepare package for lazy loading
** help
No man pages found in package ‘SOexample’
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (SOexample)