Download datasets from the SCTO validation tests repository
Source:R/get_test_data.R
get_test_data.Rd
Tests sometimes require specific datasets. Where a built-in dataset is insufficient, a dataset that exists within the SCTO validation tests repository can be downloaded.
Details
This function can be used in the setup-pkg.R file so that the datasets are available to the tests.
The function will download the dataset from the SCTO validation tests repository to the working directory, which testthat sets to the directory containing the test files. Therefore, the dataset can be downloaded and saved and used without referring to any other directory. The setup-pkg.R file might then contain:
...
library(testthat)
get_test_data("mtcars.csv")
dat <- read.csv("mtcars.csv")
withr::defer({})
Examples
# download the file to a temporary directory
tempdir <- tempdir()
get_test_data("mtcars.csv", dir = tempdir)
dat <- read.csv(file.path(tempdir, "mtcars.csv"))
unlink(tempdir)
if (FALSE) { # \dontrun{
# within the setup-pkg.R file
get_test_data("mtcars.csv")
# then load the data using an appropriate function
dat <- read.csv("mtcars.csv")
} # }