10

I am using testthat to write unit tests for my R packages. I have seen a few package authors (like those from Rcpp and ggplot2) distributing their unit tests with the binary files. However, when I build my packages with RStudio (0.98.1102) and devtools (1.7.0) the tests folder is not included in the zip file. Do I have to add the folder manually or is it possible to get this done automatically by setting some option?

BTW: I am on a Win7 machine using R v3.1.2 and RTools v3.1.0.1942.

cryo111
  • 4,444
  • 1
  • 15
  • 37

2 Answers2

10

Got it. Found the information on the github page of testthat (it's at the very bottom). https://github.com/hadley/testthat

The advantage of this new structure is that the user has control over whether or not tests are installed using the --install-tests parameter to R CMD install, or INSTALL_opts = "--install-tests" argument to install.packages(). I'm not sure why you wouldn't want to install the tests, but now you have the option.

The command to build the binary package WITH the tests is

devtools::build(binary=TRUE, args=c("--preclean", "--install-tests"))
cryo111
  • 4,444
  • 1
  • 15
  • 37
  • 1
    Do you know a way to do this directly from GitHub e.g. with `devtools::install_github`? I don't think `devtools::build` will accept a URL path. – Danny Mar 04 '22 at 16:26
  • The referenced section has been removed in [Sept 2015](https://github.com/r-lib/testthat/commit/0a7d2). – Berry Boessenkool May 11 '22 at 20:33
1

On Windows, you need code like

install.packages("dwdradar", INSTALL_opts = "--install-tests", type="source")

Without the type option, the test folder is not installed.

Berry Boessenkool
  • 1,506
  • 11
  • 15