r - 使用匹配时 dplyr 与 testthat 包发生冲突

标签 r dplyr testthat

我收到错误,因为 testthat::matchesdplyr::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/

相关文章:

python - 如何以最佳(Pythonic)方式编写这段代码?

r - 在 dplyr 中使用变量列名 (do)

r - 获取与 7 天前日期 'Around' 相关的分数

r - 测试软件QuickCheck有R接口(interface)吗?

r - 由于〜/.Rprofile,在 check() 上测试错误,但在 test() 上没有错误?

r - R 中 x 轴上标签的季节性图变化

r - tidyverse 解决方案,用于将多个列重新编码为新列,其中列名后缀增加一

调试 littler/Rscripts

r - 为什么 left_join 产生 NA 值