5

I have to check whether a package (let's call it foo) can be installed. As usual, I use R CMD check foo and wait for the check to arrive at the stage where * checking whether package "foo" can be installed... leads to an error (or not) and then navigate to 00install.out to see the errors. Unfortunately, R CMD check spends a significant amount of time on things I'm not interested at this point of the development process, e.g., * checking package dependencies .... Can this be avoided? (for example, by specifying an option to omit checking dependencies?) Or is there any other way to just check whether the package installs?

Note: I am only interested in speeding up the check before the check whether the package can be installed is executed. Everything thereafter I don't care as this is a) fast; b) not needed to be run very often and c) can be aborted anyways (at this point of the development).

Marius Hofert
  • 6,546
  • 10
  • 48
  • 102
  • 1
    Did you check the options in `R CMD check -h`? There are for example `no-examples` and `no-manual` options which might speed up things. Haven't seen a switch for package dependencies though... – user1981275 Mar 09 '15 at 15:59
  • ... all I found there are things that come *after* checking dependencies... – Marius Hofert Mar 09 '15 at 16:12
  • I think this was essentially answered here: https://stackoverflow.com/questions/29776802/possible-to-install-a-package-without-installing-dependencies. You can't install R packages without checking for (and installing) dependencies. And I also don't think it's possible to tell R CMD check to skip package installation – Ethan Bass Apr 29 '23 at 18:58
  • Actually, it looks like you can do something like this using the `--no-install` argument. This will seemingly skip any tests that involve actually running your code (e.g. test files, examples and vignettes), but will still do basic checks for proper package structure and documentation. – Ethan Bass May 02 '23 at 03:19
  • Or, if you just want to know if the package can be installed, why not just try to install the package and see if it errors out (e.g. by running `install.packages(".", repos=NULL, type="source")` – Ethan Bass May 02 '23 at 03:28
  • 1
    @EthanBass, can you collate these comments into an answer? – Ben Bolker May 02 '23 at 12:59
  • I wrote about some aspects of this years ago: One, [use binaries (instead of building depends from source)](http://dirk.eddelbuettel.com/blog/2017/12/13#013_faster_package_installation_two). Two, [use `ccache` (for faster compilation)](http://dirk.eddelbuettel.com/blog/2017/11/27#011_faster_package_installation_one). – Dirk Eddelbuettel May 02 '23 at 15:12

2 Answers2

1

I'm pretty sure there's no way to install a package without checking for and installing any package dependencies (also see Possible to install a package without installing dependencies?).

If you just want to know if the package can be installed however, you could just try to install the package (without running R CMD check) and see if it errors out (e.g. by running install.packages(".", repos=NULL, type="source"). The installation will fail if there are major problems with your package (such as a missing NAMESPACE file). Of course, this will not run any of the additional checks included in R CMD check (e.g. to check that the functions in your package don't reference non-existent variables).

Alternatively, if you want to run R CMD check but skip the installation of the package, you can use the --no-install argument. This will skip any of the tests that involve actually running your code (e.g. directly running test files, examples and vignettes), but will still perform many of the basic checks for proper package structure and documentation. In testing with one of my R packages, including the --no-install argument cut the runtime of R CMD check in half. You can also use this option in devtools by running devtools::check(args = "--no-install").

Ethan Bass
  • 426
  • 3
  • 7
0

Extending Ethan Bass' answer, one can cherry-unpick bottlenecks in the check-install-testing of packages, by using command line arguments and environment variables passed to R CMD check.

The following unpicks checking package dependencies that can take 2-3 until timeout when the internet connection is poor. It mimics a devtools::check-style workflow that:

  1. runs in a background job
  2. runs R CMD check without installing
  3. tries to install in a temporary .Library
  4. runs tests (here tinytest API, replace if needed)
t <- function(pkg) {
    job::job({
        path <- tempdir()
        rcmdcheck::rcmdcheck(args = "--no-install")
        tryCatch({
            cat("Installing package\n")
            install.packages(".",  repos = NULL, type = "source", quiet = TRUE, lib = path)
        }, warning = \(w) stop("package installation failed."))
        suppressPackageStartupMessages(tinytest::test_package(pkg, lib.loc = path))
        job::export("none")
    })
}

t("mypkg")
Donald Seinen
  • 4,179
  • 5
  • 15
  • 40