Install dependencies of custom package

I have developed a local package that depends on others available on CRAN (as an example, pool ). Therefore, when I attempt to install the package using the standard

install.packages("/path/to/package",
                 repos = NULL,
                 type = "source")

I get an error because the dependencies aren't installed. install.packages has an argument dependencies which by default would try to install those dependencies. However, as stated by the man page (and commented in the linked question below), repos = NULL means the dependencies are ignored.

To get around that, I used package miniCRAN to create a repo containing my package, hoping I could do a repos = c("myRepo", getOption("repos")) to get it to work.

Now I can install my package using

install.packages("package",
                 repos = c("/path/to/repo", getOptions("repos"),
                 type = "source")

But only if I've already installed pool . If not, I still get an error because it can't find the dependencies.

So I called miniCRAN::addPackage("pool") , which adds that package and its many dependencies to my repo, and they all appear if I call miniCRAN::pkgAvail() .

However, if I attempt to install my package again, I still get a there is no package called 'pool' error.

Interestingly, if I try to install pool itself from the repo, it works.

install.packages("pool",
                 repos = "/path/to/repo",
                 type = "source")
install.packages("package",
                 repos = "/path/to/repo",
                 type = "source")

Obviously, however, this kind of beats the point of adding pool to the repo: I might just as well have installed it from CRAN.

So what's going on here, and is this really the only way to install local packages and their CRAN dependencies?

Not sure whether that really answers your question: I generally use remotes::install_local(), maybe its source code can help.

1 Like

Thanks for the reply. Unfortunately remotes::install_local (and devtools::install, which I've also seen suggested) doesn't work either, same problem:

remotes::install_local("/path/to/pkg")
√  checking for file 'temp_path/DESCRIPTION' ...
-  preparing 'pkg':
√  checking DESCRIPTION meta-information ... 
-  checking for LF line-endings in source and make files and shell scripts
-  checking for empty or unneeded directories
-  building 'pkg_0.0.0.9004.tar.gz'
   
Installing package into β€˜.../Documents/R/win-library/3.6’
(as β€˜lib’ is unspecified)
* installing *source* package 'pkg' ...
** using staged installation
** R
** byte-compile and prepare package for lazy loading
Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) : 
  there is no package called 'pool'

Well, I just figured it out:

I'm using roxygen for my documentation and assumed it also takes care of the Imports: section of the DESCRIPTION file.

It doesn't. So as the output of remote::install_local() says, it checked my DESCRIPTION, didn't find pool in the Imports: list and so didn't install it. All I had to do was fix this oversight and now remotes::install_local works just fine.

1 Like