I want to add a local package dependency using R devtools.
The suggested way to add packages to the package DESCRIPTION file is one of the two functions use_package() and use_dev_package(), from the usethis package. The latter adds a dependency on an in-development package. The function help shows the following prototype:
use_dev_package(package, type = "Imports", remote = NULL)
where remote is
a character string to specify the remote, e.g. ‘"gitlab::jimhester/covr"’, using any syntax supported by the remotes package.
The remotes vignette shows the following
# Local
Remotes: local::/pkgs/testthat
So the command should be along these lines:
use_dev_package(foopack, type = "Imports", remote = "local::<foopack>")
However, what should be the path to the foopack. An absolute one or relative to project dir? The root package directory or the R directory with the code, or perhaps the foopack.tar.gz build?
All attempts failed for me.
Needless to say that, beyond having the local dependency properly listed in the DESCRIPTION file, I need it to be seen by the devtools build & check functions.
As regards use_dev_package(), I found a solution:
if I use devtools::check(), then the dependency appears in the search path, and use_dev_package() does not complain any more (see answer below).
However, it is still unclear to me what arguments should I use to make a development check() for the main package, in particular when the package has a vignette.
Ideally, I should be able to pass the check with local dependencies by passing cran = FALSE, but this still gives
"Package required but not available".
Let us assume that your main package depends on a local package `foopack".
To declare this dependency, first, install the dependency package from the local source:
install.packages("path/to/foopack", repos = NULL)
Then add the local package dependency twice to the package DESCRIPTION file, in the Imports and in the Remotes sections, like below (adjust the local:: path as needed):
Imports:
foopack,
Remotes:
local::../foopack
The DESCRIPTION file editing can also be automated with the package usethis:
usethis::use_dev_package("foopack", remote ="local::../foopack")
Now, devtools::check() gives no errors/warnings.
Of course, if checking for CRAN incoming feasibility with:
devtools::check(incoming = TRUE, remote = TRUE)
one gets
Unknown, possibly misspelled, fields in DESCRIPTION:
‘Remotes’
Strong dependencies not in mainstream repositories:
foopack
since Remotes is not an official description field and dependencies should be publicly available for submission on CRAN,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With