Skip to contents

This function scans all files in the specified R directory based on its name, excluding some based on the patterns provided in the ignore argument, and creates testthat files if they are missing. Useful for when many source code files were created from rapid development and unit testing has yet to be setup.

Usage

initTestthat(
  rDir = "R",
  testDir = file.path("tests", "testthat"),
  .ignore = c("-package.R$", "-class.R$", "^data.R$", "^zzz.R$", "^RcppExports.R$"),
  ignore = NULL
)

Arguments

rDir

The directory containing R source files. Default is "R".

testDir

The directory where testthat files should be created. Default is "tests/testthat".

.ignore

A character vector specifying regex patterns of files to ignore. Defaults to common patterns c("-package.R$", "-class.R$", "^data.R$", "^zzz.R$", "^RcppExports.R$")

ignore

A character vector of extra regex patterns of R files to ignore

Value

No return value, called for side effects.

Examples

# \donttest{
try({

initTestthat()
initTestthat(rDir = "src", testDir = "tests")
initTestthat(ignore = c("^foo", "-bar.R$"))

}, silent = TRUE)
#>  Setting active project to "/home/runner/work/FastUtils/FastUtils".
#> ! Package testthat is already listed in Imports in DESCRIPTION; no change made.
#>  Leaving tests/testthat.R unchanged.
#>  Call `usethis::use_test()` to initialize a basic test file and open it for
#>   editing.
#> ! Package testthat is already listed in Imports in DESCRIPTION; no change made.
#>  Leaving tests/testthat.R unchanged.
#>  Call `usethis::use_test()` to initialize a basic test file and open it for
#>   editing.
#> ! Package testthat is already listed in Imports in DESCRIPTION; no change made.
#>  Leaving tests/testthat.R unchanged.
#>  Call `usethis::use_test()` to initialize a basic test file and open it for
#>   editing.
# }