我得到一個錯誤,因爲testthat::matches
衝突與dplyr::matches
,我想知道如何使用testthat::test_file
檢查其包含對matches()
通話功能,而無需在函數體中指定dplyr::matches
testthat包。dplyr上有衝突時,比賽用
例如爲:
> testthat::test_file('tmp_fn_testthat_test.R')
Attaching package: ‘testthat’
The following object is masked from ‘package:dplyr’:
matches
The following object is masked from ‘package:purrr’:
is_null
Show Traceback
Rerun with Debug
Error in -matches("tmp") : invalid argument to unary operator In addition: Warning message:
package ‘testthat’ was built under R version 3.2.5
DONE =========================================================================================================================================
這個錯誤可以通過保存在你的工作目錄名爲tmp_fn_testthat_test.R
文件下面的代碼,並運行該命令testthat::test_file('tmp_fn_testthat_test_20161115.R')
轉載。請注意,採購或運行expect_equal
命令,而未加載testthat
會使測試通過。
tmp_fn <- function() {
tmp_df <- data.frame(tmp_a = 1, tmp_b = 2)
tmp_df %>%
select(-matches('tmp')) %>%
ncol
}
testthat::expect_equal(tmp_fn(), 0)
我理解,但我的問題這裏是我明確地嘗試不用通過在'testthat ::'前面加載所有測試來加載'testthat',這樣如果我輸入文件,測試就可以工作。無論什麼原因,當你運行'testthat :: test_file'時,它堅持加載包。 – Alex