Closed MxNl closed 2 years ago
I have now posted it also here: https://community.rstudio.com/t/difference-between-devtools-check-and-devtools-test-regarding-usage-of-test-data/130561 I will close this issue, if it gets answered in RStudio community.
I believe testthat::test_path()
is the solution you seek.
This GitHub search is rich in examples of how people use it:
https://github.com/search?q=test_path+path%3Atests+org%3Acran
I believe
testthat::test_path()
is the solution you seek.
Thanks a lot!!! I'll try it out. It would be great to have an example of that in the R Packages book. After an average web search I didn't come across that function. According to the lack of solutions in relevant questions on SO, others have difficulties to find it, too. But thanks a lot so far! Greetings from Berlin!
The testing chapter has not been revised yet for the 2nd edition but will be.
In my case, the contents of inst/testdata
was moved to a folder Package.Rcheck/Package/test-data/
when running devtools::check()
. This difference in working directory broke the absolute path to the test data. I did a pattern match with grepl
to handle this case. Not elegant but it worked.
In my case, the contents of
inst/testdata
was moved to a folderPackage.Rcheck/Package/test-data/
when runningdevtools::check()
. This difference in working directory broke the absolute path to the test data. I did a pattern match withgrepl
to handle this case. Not elegant but it worked.
Ok, but why not using jennybc's solution. It's easy and works. Data in subfolder of tests/testthat and then refer to it with testthat::test_path()
.
Hello,
in my currently developed package I want to use data (several .tif files) for unit testing with testthat. I read in R Packages that the recommended solution is to put it into the tests directory. Additionally, I read this thread on Stackoverflow. I put it in
In one of my testfiles I test a function that gets the directory where the test data lives as argument. I provided this directory using
When running the test using devtools::test() everything is fine but when running devtools::check() or using control + shift + E this directory is not found. After printing the root directory during testing it seems that the directory "test" doesn't exist. I didn't expect this to be an edge case, but from the usual web research it seems like it.
I would really appreciate any hint. Thanks a lot!