0

Short question

I am building a package foo. I want to distribute the binary package for foo. Does installing the binary package using the following command automatically install the dependencies? Is there a way to distribute the binary package so that the users don't have to explicitly install dependencies?

install.packages("foo_1.0.zip", type="win.binary", dependencies=TRUE)

details:

I am using R4.2.2 on Windows.

I build the package using:

R CMD INSTALL --build foo 

resulting in `foo_1.0.zip

foo depends on the package collections.

DESCRIPTION file contains the following line Imports: collections(>= 0.3.6)

NAMESPACE File contains the following line: importFrom(collections, dict)

If a user doesn't have the package collections installed, and tries to install foo on Windows using install.packages("foo_1.0.zip", type="win.binary", dependencies=TRUE), the package collections is not automatically installed but the installation for foo succeeds without any error. When the user tries to use it with library(foo), they get the following error because of the importFrom line in NAMESPACE.

Error: package or namespace load failed for 'foo' in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):
 there is no package called 'collections'

I don't plan to distribute the package on CRAN.

  • 1
    R can do all this for you, as it does on CRAN _and on other repositories_. You can hold all the (added) dependencies in a local repository. Many of us managed such repositories in labs or workplaces. I wrote a helper package too I (and many others) find useful: [drat](https://github.com/eddelbuettel/drat) – Dirk Eddelbuettel Feb 24 '23 at 20:08
  • Normally to install from a local file you need to set `repos=NULL` in `install.packages()`. Since `repos` is NULL it cannot automatically install dependencies for you in that case. I'm surprised it worked without it but I don't have a Windows machines to test with. – MrFlick Feb 24 '23 at 20:08
  • @DirkEddelbuettel so I get that there is no "ready" way to do this directly using install.packages(). EIther you hold the dependencies in your package (using some scripts_ or manually install those. Am I right in saying that? MrFlick That makes sense. Thanks. – optimizationguy Feb 24 '23 at 20:16
  • 1
    Try `devtools::install_local("mypackage.tar.gz")` That will install the source package in the indicated file and all dependencies from CRAN. – G. Grothendieck Feb 24 '23 at 20:33
  • No that is not at all what I am saying. You can set up a repo containing source (or binary, if you build them) packages B, C, D, and E that your package A depends upon. (Of course you install A in the repo.) Then, `install.packages("A")` will install all of them, "automagically", if you declare the dependencies (as you would at CRAN). And `drat` helps you put that repository together. – Dirk Eddelbuettel Feb 24 '23 at 20:34
  • Oh, that makes sense. Thanks Dirk. Many of your answers have helped me a lot! @Grothendieck, thanks. It works too, fantastic solution. – optimizationguy Feb 24 '23 at 20:37

0 Answers0