Install R package with specific version AND tests
Asked Answered
L

1

7

I would like to run the package-internal tests with testthat::test_package('httr') on a specific version of a package. Is there a way to install a R package (e.g. from CRAN) with a specific version AND it's tests?

I know there is install.packages("httr", INSTALL_opts = "--install-tests") to install the tests for the given package (without any option to specify a specific package version).

And there is devtools::install_version("httr", version = "1.4.1") or renv::install("[email protected]") to install a specific version for a package (without the possibility to specify e.g. the INSTALL_opts).

I don't see any way to combine the specification of the package version and the --install-tests option. Any help would be appreciated!

Note: The package "httr" was just used as a placeholder here.

Lamonica answered 23/8, 2021 at 10:6 Comment(0)
M
7

renv provides a small extension where these options can be set via the INSTALL_opts R option. So, for example, the following should work with renv 0.14.0:

# set options for renv
options(INSTALL_opts.httr = "--install-tests")

# use 'rebuild = true', in case an older version
# of the package without tests is cached
renv::install("[email protected]", rebuild = TRUE)

If you wanted these options to apply to all package to be installed, you could instead use:

options(INSTALL_opts = "--install-tests")

(renv supports setting these via options mainly so that package installation via renv::restore() can be configured more ergonomically on a per-package basis.)

Marcelo answered 23/8, 2021 at 16:31 Comment(1)
Thank you very much. I was not aware that the package name can be added to the options so that the option only applies to a single package! Additionally, I was not aware of the rebuild=TRUE option. Thanks!Lamonica

© 2022 - 2024 — McMap. All rights reserved.