Wasabi
Wasabi

Reputation: 3071

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?

Upvotes: 2

Views: 336

Answers (1)

Wasabi
Wasabi

Reputation: 3071

Figured it out.

The problem was a misunderstanding on my part regarding roxygen, which I've been using for my documentation. I assumed it handled the Imports: section of the DESCRIPTION file, which it doesn't ((1), (2)). So while the NAMESPACE file has all the necessary importFrom(pool, ...) calls, pool wasn't actually on my DESCRIPTION.

After fixing that oversight, using remote::install_local("path/to/pkg") (or devtools::install()) ((3)) worked: it installed my package and pulled its dependencies from CRAN.

Upvotes: 1

Related Questions