Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run devtools::test from the command line?

Tags:

r

devtools

One of my tests is failing, and I want to use git bisect to track it down.

For that, I need to run devtools::test from the command line in such a way that the process exit code would indicate whether all tests have passed.

How do I do that?

like image 255
Roman Cheplyaka Avatar asked Feb 09 '23 05:02

Roman Cheplyaka


1 Answers

On the command line, the standard package build workflow is to create a package tarball using R CMD build and then check it using R CMD check. devtools simply runs this workflow for you using system() calls. What would this look like for you:

R CMD build dirname
R CMD check pkgname_version.tar.gz

This will give an appropriate status code depending on whether all checks are successful or not. If you just want to check tests (and not other package features), then you'll have to explore the R CMD check options. Those will enable you to turn off (some of) the other specific checks, such as documentation examples, vignettes, building a PDF of documentation, etc.

The current listing of these options (for R2.3.3) is:

> R CMD check --help
Check R packages from package sources, which can be directories or
package 'tar' archives with extension '.tar.gz', '.tar.bz2',
'.tar.xz' or '.tgz'.

A variety of diagnostic checks on directory structure, index and
control files are performed.  The package is installed into the log
directory and production of the package PDF manual is tested.
All examples and tests provided by the package are tested to see if
they run successfully.  By default code in the vignettes is tested,
as is re-building the vignette PDFs.

Options:
  -h, --help            print short help message and exit
  -v, --version         print version info and exit
  -l, --library=LIB     library directory used for test installation
                        of packages (default is outdir)
  -o, --output=DIR      directory for output, default is current directory.
                        Logfiles, R output, etc. will be placed in 'pkg.Rcheck'
                        in this directory, where 'pkg' is the name of the
                        checked package
      --no-clean        do not clean 'outdir' before using it
      --no-codoc        do not check for code/documentation mismatches
      --no-examples     do not run the examples in the Rd files
      --no-install      skip installation and associated tests
      --no-tests        do not run code in 'tests' subdirectory
      --no-manual       do not produce the PDF manual
      --no-vignettes    do not run R code in vignettes nor build outputs
      --no-build-vignettes    do not build vignette outputs
      --run-dontrun     do run \dontrun sections in the Rd files
      --run-donttest    do run \donttest sections in the Rd files
      --use-gct         use 'gctorture(TRUE)' when running examples/tests
      --use-valgrind    use 'valgrind' when running examples/tests/vignettes
      --timings         record timings for examples
      --install-args=   command-line args to be passed to INSTALL
      --test-dir=       look in this subdirectory for test scripts (default tests)
      --check-subdirs=default|yes|no
                        run checks on the package subdirectories
                        (default is yes for a tarball, no otherwise)
      --as-cran         select customizations similar to those used
                        for CRAN incoming checking

The following options apply where sub-architectures are in use:
      --extra-arch      do only runtime tests needed for an additional
                        sub-architecture.
      --multiarch       do runtime tests on all installed sub-archs
      --no-multiarch    do runtime tests only on the main sub-architecture
      --force-multiarch run tests on all sub-archs even for packages
                        with no compiled code

By default, all test sections are turned on.

Report bugs at bugs.r-project.org .

Note: For R CMD check, you have to manually specify the package version number (which will be based on the value of Version in your package DESCRIPTION file). If you only have one package tarball being built in the directory, you could use wildcards to create a reusable workflow:

R CMD build dirname
R CMD check pkgname*.tar.gz

Remember also that if you're planning on shipping the package to CRAN, that you should also run checks with the --as-cran option, which runs some additional checks.

like image 117
Thomas Avatar answered Feb 16 '23 04:02

Thomas