我收到错误,因为 testthat::matches
与 dplyr::matches
冲突,我想知道如何使用 testthat::test_file
检查包含对 matches()
调用的函数,而无需在函数体中指定 dplyr::matches
。
例如:
> 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') 来重现此错误
。请注意,在未加载 testthat
时获取或运行 expect_equal
命令会使测试通过。
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)
最佳答案
This is a known issue dplyr 0.5。推荐的解决方案是使用显式命名空间前缀:dplyr::matches
。
关于r - 使用匹配时 dplyr 与 testthat 包发生冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40601061/