【发布时间】:2016-11-16 06:52:09
【问题描述】:
因为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)
【问题讨论】: