building and testing package

-- Test failures ------------------------------------------------- testthat ----

> library(testthat)
> library(ExtractTrainData)
> library(raster)
Loading required package: sp
> test_check("ExtractTrainData")
Error in test_files(paths, reporter = reporter, env = env, stop_on_failure = stop_on_failure,  : 
  No matching test file in dir
Calls: test_check -> test_package_dir -> test_dir -> test_files
Execution halted

2 errors x | 0 warnings v | 0 notes v
Error: R CMD check found ERRORs
Execution halted

Exited with status 1.

unable to add external data for test packages
I want to add a raster data
and a shapefile

See the External Data section of R-pkgs, and/or the data section of Writing R Extensions

1 Like

The resource cited by @mara should contain the general information on including data into your package.

It sounds like you're having issues finding files on disk in your package. I currently add a shape file into one of my packages under inst/extdata/. I access it by first sorting out the path using `system.file("extdata","my_file.sf", package="my_package_name"), then supply that path to the function that reads shape files from disk.

no sir, I am making a package and I want to add external data for testing my package using testthat. but I am unable to add those datasets from my disk to my package. and I got this error

not working still now can't add dataset for testthat

1 . Put some data file at inst/extdata/mydata.csv in your package.

2 . In your test, get the path the the data file using the system.file function.
E.g. in tests/testthat/test_load_data.R:

testthat("Locating data file in package", {
  test_data_path <- system.file("extdata", "mydata.csv", package="yourPackageName")
  expect_true( file.exists(test_data_path) )
  1. Run your tests with devtools::test() or whatever post build testing setup you have.