R CMD check / devtools::test() and the current working directory

对着背影说爱祢 提交于 2019-12-25 07:01:04

问题


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!

来源:https://stackoverflow.com/questions/35973359/r-cmd-check-devtoolstest-and-the-current-working-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!