Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

floor_date error when used with curly curly rlang #959

Closed
user63230 opened this issue Mar 9, 2021 · 4 comments · Fixed by tidyverse/dplyr#5814
Closed

floor_date error when used with curly curly rlang #959

user63230 opened this issue Mar 9, 2021 · 4 comments · Fixed by tidyverse/dplyr#5814

Comments

@user63230
Copy link

When I use curly curly {{}} with floor_date I run into an apparent bug as mentioned here on SO.

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
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

@akrun suggests there is a clash with lubridate function floor_date because group_by(month = month({{date_varaible}})) works.

As described on the SO question, the fact that it used to work also suggests that it is a bug.

@vspinu
Copy link
Member

vspinu commented Mar 11, 2021

@user63230 I don't know why {{ is not working here. As far as I can judge it should work; !!ensym() does work here. I think this issue is more appropriate for rlang proper, especially that you claim it used to work before. Could be a bug there. cc @lionel-

@lionel-
Copy link
Member

lionel- commented Mar 11, 2021

This is a bug in dplyr which will be fixed once tidyverse/dplyr#5814 is merged.

lionel- added a commit to tidyverse/dplyr that referenced this issue Mar 11, 2021
@vspinu
Copy link
Member

vspinu commented Mar 11, 2021

Amazing, thanks!

@user63230
Copy link
Author

thanks!

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Jun 12, 2021
# dplyr 1.0.6

* `add_count()` is now generic (#5837).

* `if_any()` and `if_all()` abort when a predicate is mistakingly used
  as `.cols=` (#5732).

* Multiple calls to `if_any()` and/or `if_all()` in the same
  expression are now properly disambiguated (#5782).

* `filter()` now inlines `if_any()` and `if_all()` expressions. This
  greatly improves performance with grouped data frames.

* Fixed behaviour of `...` in top-level `across()` calls (#5813, #5832).

* `across()` now inlines lambda-formulas. This is slightly more performant and
  will allow more optimisations in the future.

* Fixed issue in `bind_rows()` causing lists to be incorrectly transformed as
  data frames (#5417, #5749).

* `select()` no longer creates duplicate variables when renaming a variable
  to the same name as a grouping variable (#5841).

* `dplyr_col_select()` keeps attributes for bare data frames (#5294, #5831).

* Fixed quosure handling in `dplyr::group_by()` that caused issues with extra
  arguments (tidyverse/lubridate#959).

* Removed the `name` argument from the `compute()` generic (@ianmcook, #5783).

* row-wise data frames of 0 rows and list columns are supported again (#5804).

# dplyr 1.0.5

* Fixed edge case of `slice_sample()` when `weight_by=` is used and there
  0 rows (#5729).

* `across()` can again use columns in functions defined inline (#5734).

* Using testthat 3rd edition.

* Fixed bugs introduced in `across()` in previous version (#5765).

* `group_by()` keeps attributes unrelated to the grouping (#5760).

* The `.cols=` argument of `if_any()` and `if_all()` defaults to `everything()`.

# dplyr 1.0.4

* Improved performance for `across()`. This makes `summarise(across())` and
  `mutate(across())` perform as well as the superseded colwise equivalents (#5697).

* New functions `if_any()` and `if_all()` (#4770, #5713).

* `summarise()` silently ignores NULL results (#5708).

* Fixed a performance regression in `mutate()` when warnings occur once per
  group (#5675). We no longer instrument warnings with debugging information
  when `mutate()` is called within `suppressWarnings()`.

# dplyr 1.0.3

* `summarise()` no longer informs when the result is ungrouped (#5633).

* `group_by(.drop = FALSE)` preserves ordered factors (@brianrice2, #5545).

* `count()` and `tally()` are now generic.

* Removed default fallbacks to lazyeval methods; this will yield
  better error messages when you call a dplyr function with the wrong
  input, and is part of our long term plan to remove the deprecated
  lazyeval interface.

* `inner_join()` gains a `keep` parameter for consistency with the other
  mutating joins (@patrickbarks, #5581).

* Improved performance with many columns, with a dynamic data mask using active
  bindings and lazy chops (#5017).

* `mutate()` and friends preserves row names in data frames once more (#5418).

* `group_by()` uses the ungrouped data for the implicit mutate step (#5598).
  You might have to define an `ungroup()` method for custom classes.
  For example, see hadley/cubelyr#3.

* `relocate()` can rename columns it relocates (#5569).

* `distinct()` and `group_by()` have better error messages when the
  mutate step fails (#5060).

* Clarify that `between()` is not vectorised (#5493).

* Fixed `across()` issue where data frame columns would could not be referred to
  with `all_of()` in the nested case (`mutate()` within `mutate()`) (#5498).

* `across()` handles data frames with 0 columns (#5523).

* `mutate()` always keeps grouping variables, unconditional to `.keep=` (#5582).

* dplyr now depends on R 3.3.0


# dplyr 1.0.2

* Fixed `across()` issue where data frame columns would mask objects referred to
  from `all_of()` (#5460).

* `bind_cols()` gains a `.name_repair` argument, passed to
  `vctrs::vec_cbind()` (#5451)

* `summarise(.groups = "rowwise")` makes a rowwise data frame even if
  the input data is not grouped (#5422).

# dplyr 1.0.1

* New function `cur_data_all()` similar to `cur_data()` but includes
  the grouping variables (#5342).

* `count()` and `tally()` no longer automatically weights by column `n` if
  present (#5298). dplyr 1.0.0 introduced this behaviour because of Hadley's
  faulty memory. Historically `tally()` automatically weighted and `count()`
  did not, but this behaviour was accidentally changed in 0.8.2 (#4408) so that
  neither automatically weighted by `n`. Since 0.8.2 is almost a year old,
  and the automatically weighting behaviour was a little confusing anyway,
  we've removed it from both `count()` and `tally()`.

    Use of `wt = n()` is now deprecated; now just omit the `wt` argument.

* `coalesce()` now supports data frames correctly (#5326).

* `cummean()` no longer has off-by-one indexing problem (@Cropgen, #5287).

* The call stack is preserved on error. This makes it possible to `recover()`
  into problematic code called from dplyr verbs (#5308).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants