Using test_package() to test packages installed with install_github()

I routinely develop small packages using devtools on a development server, where I run test() before pushing to GitHub and then deploying to a staging server.

Compared to the development server, the environment and the set of installed packages can be different on the staging server (I do not administer both). So, I would like to do the following on the staging server as a quick check:


However, I get the following:

No installed testthat tests found for foo

If I run:

dir(file.path(.libPaths()[1], "foo"))

... I can see that there is no tests/ subdirectory.

Can I pass some sort of argument to install_github("myorg/foo", ...) that will force installation of the test suite, so that I can then use test_package("foo", ...) to test it "as installed" on the staging server?

There is a tests/ directory in the repository on GitHub, so install_github() should in theory have access to that.

Yes, the installation option you need is --install-tests and you can pass it to install.packages(), which is called by devtools::install_github() by using the INSTALL_opts argument.

So your call will look like

devtools::install_github("myorg/foo", INSTALL_opts = "--install-tests")

However generally I would not recommend doing what you propose.

Instead I would recommend running a full R CMD check by using devtools::check(), which also runs the tests as part of the check among a host of other useful checks.