0

I am working on a R package that has some functions that I want to test (locally) on data that I can't distribute, because the data source is proprietary.

I have a folder (paid_projections) where I'm keeping those files. This caused some initial difficulties when running devtools::test() and R CMD check, I think because of subtle differences in the working directory that those utilities seen.

I've solved this problem by having my tests make some ad-hoc fixes to the path:

spec_file <- file.path('paid_projections', 'pod_projections.xlsx')
file_loc <- file.path(getwd(), spec_file)
#for CMD check
file_loc <- gsub('.Rcheck', '', file_loc, fixed = TRUE)
#for devtools::test()
file_loc <- gsub('tests/testthat/', '', file_loc, fixed = TRUE)
ex <- read_raw_pod(file_loc)

This... is less than ideal, and kind of makes me want to go take a shower. It does create the behavior that I want (I can run these tests in the console, via devtools::test(), or R CMD check), but it doesn't feel like the correct solution.

There's a devtools::wd() command that seems like it might be helpful here, but I couldn't quite make sense of how that might replace the eyesore above. Would love any suggestions!

Andrew
  • 9,090
  • 8
  • 46
  • 59
  • Does `R CMD check` really work? I assume you don't put these files into your package (.tar.gz) that's why it could not really work. At least not on CRAN. – sgibb Mar 13 '16 at 19:02
  • Good q, I'm not planning on submitting it to CRAN in the near-term, just using CMD check for code health / test-driven-development practices. The RStudio/devtools/local version of it works. Wouldn't work on CRAN, though. – Andrew Mar 13 '16 at 19:04
  • 1
    At least for `devtools` you could do the following: put the data into `inst/paid` and add `inst/paid` to `.Rbuildignore` and `.gitignore`. Then you could use `system.file("paid", package="mypackage")` (it is overwritten by `devtools`) to get the correct path in the tests. I don't think this will work for `R CMD check` because `.Rbuildignore` prevent R from putting the data into the `tar.gz`. – sgibb Mar 13 '16 at 19:08

0 Answers0