报错信息如下:
Error in UseMethod("filter_") :
no applicable method for 'filter_' applied to an object of class "character"
Calls: %>% ... freduce -> <Anonymous> -> filter -> filter.default -> filter_
In addition: Warning message:
`filter_()` is deprecated as of dplyr 0.7.0.
Please use `filter()` instead.
See vignette('programming') for more help
This warning is displayed once every 8 hours.
Call `lifecycle::last_warnings()` to see where this warning was generated.
Execution halted
最开始我以为这个method是我用错了成filter_,
后面经过查询脚本和网上资料才知道,是因为输入的文件不是tibble、data.frame格式。
情况1: 忘记读入文件了,我是因为这个原因报错
file <- args[1]
情况2:当然还有可能是输入的是matrix,这时候需要把matrix转换成data.frame格式
例子如下
> a <- matrix(1:9, ncol =3)
> colnames(a) <- c("test1","test2","test3")
> a
test1 test2 test3
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9
> filter(a, test1 == 2)
报错信息
转换成为tibble/data.frame这个报错就没有了
> filter(as_tibble(a), test1 == 2)
# A tibble: 1 x 3
test1 test2 test3
<int> <int> <int>
1 2 5 8
参考ref:(感谢参考帖子)
https://stackoverflow.com/questions/57286838/how-to-fix-dplyr-filter-error-in-usemethodfilter