我无法在 dplyr 的过滤器表达式中使用公式或 quosures。
a_table <- data_frame(key = rep(letters[1:2], each = 2),
value = replace(runif(4), mod(1:4, 2) == 1, NA))
a_cond <- quo(not(is.na(value)))
filter(a_table, !!a_cond)
产生错误
Error in filter_impl(.data, dots) : invalid argument type
我已经阅读了 NSE 和 dplyr 编程的小插曲,并尝试了不同的调用:
a_cond <- interp(~not(is.na(value_)), value_ = as.name("value"))
但还没有真正做到。
谢谢您的帮助。
会话信息是:
> sessionInfo()
R version 3.4.2 (2017-09-28)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 17.10
other attached packages:
[1] rlang_0.1.1 readxl_1.0.0 aws.s3_0.3.3 magrittr_1.5
[5] dplyr_0.5.0 ggplot2_2.2.1 tidyr_0.6.1 dtplyr_0.0.2
[9] lazyeval_0.2.0 purrr_0.2.2.2 data.table_1.10.4 feather_0.3.1
[13] readr_1.1.0 lubridate_1.6.0 stringr_1.2.0