Save R objects to separate files tests/testthat/testdata in the .rds format.

use_testdata(
  ...,
  subdir = NULL,
  overwrite = FALSE,
  ignore = FALSE,
  compress = TRUE,
  refhook = NULL,
  version = NULL
)

use_testdata_raw(name = NULL)

has_testdata()

read_testdata(infile, subdir = NULL)

find_testdata(..., path = ".", must_exist = FALSE)

Arguments

...

R objects to save to the testdata dir. If empty, an empty directory is created.

subdir

character scalar. Subdirectory of testdata to save to / read from.

overwrite

Logical scalar. Should existing files be overwritten?

ignore

Should the newly created file be added to .Rbuildignore?

compress

a logical specifying whether saving to a named file is to use "gzip" compression, or one of "gzip", "bzip2" or "xz" to indicate the type of compression to be used. Ignored if file is a connection.

refhook

a hook function for handling reference objects.

version

the workspace format version to use. NULL specifies the current default version (3). The only other supported value is 2, the default from R 1.4.0 to R 3.5.0.

name

a character scalar or NULL. Name of the dataset for which to create a script file in testthat/testdata-raw. If NULL an empty testthat/testdata-raw directory is created (if it does not exist already).

infile

rds file to read (must end in .rds, otherwise .rds ending is automatically added)

path

Path of the directory to create, relative to the project.

must_exist

logical scalar. Assert that path specified in ... exists

Value

use_testdata() returns TRUE if object was successfully saved.

has_testdata() returns TRUE if package has a tests/testthat/testdata folder.

read_testdata() returns a single R object

find_testdata() returns the normalized path to a file in a in the testdata directory

Side effects

use_testdata() saves an R object to a testdata dir in the current package.

See also

base::readRDS()

Other infrastructure: use_test_subdir(), use_tester()

Examples

if (FALSE) { use_testdata(letters, LETTERS) }