Possible bug with tidyverse (encountered while changing monthly data to daily with `expand`)

I have the following monthly data (ymd format) that I want to convert to daily format:

df <- structure(list(date = structure(c(12053, 12084, 12112, 12143, 
12173, 12204, 12234, 12265, 12296, 12326), class = "Date"), adjustment = c(1.55630887185104, 
1.54783224400871, 1.54530723219141, 1.55121179039301, 1.55375615090213, 
1.55205898416166, 1.54698965704954, 1.54028184281843, 1.53528903295516, 
1.53694970254191)), row.names = c(NA, -10L), class = c("tbl_df", 
"tbl", "data.frame"))

and my code is:

df %>% group_by(date) %>% expand(date = seq(floor_date(date, unit = "month"), ceiling_date(date, unit="month") - days(1), by="day"))

This code appears to have worked for R 4.1.2, on Windows on an old but I am on version R version 4.2.1 (2022-06-23) on macOS and I get the following error:

Error in `dplyr::summarise()`:
! Problem while computing `..1 = expand(data = dplyr::cur_data(), ..., .name_repair = .name_repair)`.
ℹ The error occurred in group 1: date = 2003-01-01.
Caused by error in `object[[name, exact = TRUE]]`:
! object of type 'closure' is not subsettable
Run `rlang::last_error()` to see where the error occurred.

Is my code outdated? Do other people get a similar error?

It doesn't work for me:

R version 4.1.2 (2021-11-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)

My code did work as of 2018, as shown here. And apparently, this happened to others as of April 2022

Do you get ..."closure" is not subsettable for an error message? Or did I mess up my reprex?

Yes.

Error in dplyr::summarise():
! Problem while computing ..1 = expand(data = dplyr::cur_data(), ..., .name_repair = .name_repair).
i The error occurred in group 1: date = 2003-01-01.
Caused by error in object[[name, exact = TRUE]]:
! object of type 'closure' is not subsettable
Run rlang::last_error() to see where the error occurred.

write it like so :

df %>%
  group_by(date) %>%
  summarise(d2 = (seq(floor_date(date, unit = "month"),
    ceiling_date(date, unit = "month") - days(1),
    by = "day"
  ))) %>%
  expand(d2)

be sure to load the libraries (tidyverse & lubridate)

Thanks.

I'd make a small edit:

df %>%
  group_by(date) %>%
  summarise(date = (seq(floor_date(date, unit = "month"),
    ceiling_date(date, unit = "month") - days(1),
    by = "day"
  )),
    adjustment) %>%
  expand()

I want to keep the adjustment column.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.