curly curly Error: Base operators are not defined for quosures

curly curly Error: Base operators are not defined for quosures

以下自定义函数以前可以使用,参见 ,但它似乎不再起作用了:

library(tidyverse)
library(rlang)
library(scales)
data1 <- data.frame(date1 = sample(seq(as.Date("2005-01-01"), as.Date('2018-01-01'), by="day"), 5),
                    num1 = 1:5)
data1
hist_date_f <- function(df, date_varaible) {
    df %>%
      group_by(month = floor_date({{date_varaible}}, "month")) %>%
      dplyr::summarize(freq = n()) %>%  
      ggplot(aes(x = month, y = freq)) + 
      geom_bar(stat = "identity") + 
      scale_x_date(labels = date_format("%m-%Y"), 
                   breaks = date_breaks ("1 month")) + 
      theme_bw()
}

hist_date_f(data1, date1)
# Error: Base operators are not defined for quosures.
# Do you need to unquote the quosure?

#   # Bad:
#   myquosure == rhs

#   # Good:
#   !!myquosure == rhs

自从导致问题的解决方案以来,肯定有一些更新。我试图用 {{ }}.

避免 enquo()!!
sessionInfo()
# attached base packages:
# [1] stats     graphics  grDevices utils     datasets  methods   base     

# other attached packages:
#  [1] scales_1.1.1    rlang_0.4.10    forcats_0.5.0   stringr_1.4.0  
#  [5] dplyr_1.0.3     purrr_0.3.4     readr_1.4.0     tidyr_1.1.2    
#  [9] tibble_3.0.5    ggplot2_3.3.3   tidyverse_1.3.0 tidylog_1.0.2

谢谢

编辑 这是 dplyr bug

报告的错误

我们可以转换为 symbol 并计算 (!!)

hist_date_f <- function(df, date_varaible) {
   df %>%
    group_by(month = floor_date(!! ensym(date_varaible), "month")) %>%
    dplyr::summarize(freq = n()) %>%  
    ggplot(aes(x = month, y = freq)) + 
   geom_bar(stat = "identity") + 
   scale_x_date(labels = date_format("%m-%Y"), 
               breaks = date_breaks ("1 month")) + 
  theme_bw()
 }

-测试

hist_date_f(data1, date1)