2017-08-25 28 views
0

我正在構建一個R軟件包RE,我想打包一個獨立腳本並將其放在RE/exec/wrapper.R中。我已經爲測試編寫了一個測試函數,它在使用devtools::test("RE")從命令行運行時工作得很好,但在使用devtools::check("RE")運行時失敗。如何使用testthat測試作爲軟件包一部分的獨立R腳本

失敗

相關的代碼部分:

cmd <- "Rscript \"C:\\RE\\exec\\wrapper.R\" base print \"{\\\"x\\\": 2}\"" 
rv <- system(cmd, intern = FALSE, ignore.stderr = FALSE, show.output.on.console = FALSE) 

當爲「測試」部分運行一切都正常運行和system回報0,因爲它應該。當作爲「檢查」的一部分運行時,system會給出下面給出的錯誤消息並返回1

Error in file(filename, "r", encoding = encoding) : cannot open the connection 
Calls: local ... eval.parent -> eval -> eval -> eval -> eval -> source -> file 
In addition: Warning message: 
In file(filename, "r", encoding = encoding) : cannot open file 'startup.Rs': No such file or directory 
Execution halted 

我:

  1. 選中該文件存在(它在這兩種情況下)
  2. 試過tryCatch。沒有錯誤被發現,並system剛剛返回1

這讓我覺得,這是systemR CMD CHECK的問題。

回答

0

答案在https://github.com/hadley/testthat/issues/144。必須在頂級測試腳本(package_root/tests/testthat.R)中通過Sys.setenv("R_TESTS" = "")取消設置環境變量R_TESTS,否則system在從R CMD CHECK調用時將無法正確運行。我離開了這個問題,因爲在絆倒答案之前,我花了幾個小時的時間進行試驗和搜索。

相關問題