Reputation: 221
I'm developing an R package that uses a dependency that is a locally stored package, and I cannot figure out how to properly list that package in the DESCRIPTION
file. The package I am building is PackageA and it depends on PackageB. PackageB is locally stored on my drive after I was shared a zip folder of it from a colleague. Both of these packages are meant to be for internal use only and will not be stored on any repositories. I found the following page that shows how this can be done using the Remotes:
tag in the DESCRIPTION
file:
https://cran.r-project.org/web/packages/devtools/vignettes/dependencies.html
This can be done with the following code, but when I try this I receive an error also shown below:
#Example from linked vignette
# Local
Remotes: local::/pkgs/testthat
#Both of these attempts produce the same error
#1. Specify file path to the unpacked version of the package in my R library
Remotes: local::C:/Users/name/library/PackageB
#2. Specify file path to the original .zip version of the package
Remotes: local::C:/Users/name/library/PackageB.zip
#devtools::build() error
ERROR: package installation failed
Error in (function (command = NULL, args = character(), error_on_status = TRUE, :
System command 'Rcmd.exe' failed, exit status: 1, stdout + stderr:
E> * checking for file 'C:\Users\name\PackageA/DESCRIPTION' ... OK
E> * preparing 'PackageA':
E> * checking DESCRIPTION meta-information ... OK
E> * installing the package to build vignettes
E> -----------------------------------
E> ERROR: dependency 'PackageB' is not available for package 'PackageA'
E> * removing 'C:/Users/tmpfolder/PackageA'
E> -----------------------------------
E> ERROR: package installation failed
#Rstudio Install and Restart error; I would build the source after this but it doesn't get that far
Error: Dependency package(s) 'PackageB' not available.
Backtrace:
x
1. +-base::suppressPackageStartupMessages(...)
2. | \-base::withCallingHandlers(expr, packageStartupMessage = function(c) tryInvokeRestart("muffleMessage"))
3. \-devtools::document(...)
4. \-roxygen2::roxygenise(pkg$path, roclets)
5. \-roxygen2:::load_code(base_path)
6. \-pkgload::load_all(path, helpers = FALSE, attach_testthat = FALSE)
7. \-pkgload:::load_imports(path)
8. \-pkgload:::abort_for_missing_packages(res, imports$package)
Warning message:
In (function (dep_name, dep_ver = "*") :
Dependency package 'PackageB' not available.
Execution halted
Exited with status 1.
I'm wondering if I'm specifying the file path incorrectly, but maybe its something more complicated.
Upvotes: 2
Views: 677
Reputation: 368519
"You can't" via the standard repo as Imports
etc need to access the package. What you can do is to create a local repo (and for example the drat
packages makes that easy), and that repo to set of known repos on the test box (add to options(repos)
, or use a drat
helper function) and test then.
Alternatively you can use the Additional_repositories
field but only for a Suggests: so you will have to test for presence before using code from that second package in the first.
And, in a nutshell, "just having the package installed" is not good enough for the tests. Just not how R thinks about packages.
Upvotes: 2