diff --git a/r/R/dplyr-funcs-datetime.R b/r/R/dplyr-funcs-datetime.R index 2eedc03ad83..0ff42944c0f 100644 --- a/r/R/dplyr-funcs-datetime.R +++ b/r/R/dplyr-funcs-datetime.R @@ -101,6 +101,10 @@ register_bindings_datetime <- function() { Expression$create("day_of_week", x, options = list(count_from_zero = FALSE, week_start = week_start)) }) + register_binding("week", function(x) { + (call_binding("yday", x) - 1) %/% 7 + 1 + }) + register_binding("month", function(x, label = FALSE, abbr = TRUE, locale = Sys.getlocale("LC_TIME")) { if (label) { if (abbr) { diff --git a/r/tests/testthat/test-dplyr-funcs-datetime.R b/r/tests/testthat/test-dplyr-funcs-datetime.R index 2aaaf5c4723..c3f79dc13ee 100644 --- a/r/tests/testthat/test-dplyr-funcs-datetime.R +++ b/r/tests/testthat/test-dplyr-funcs-datetime.R @@ -385,6 +385,15 @@ test_that("extract epiweek from timestamp", { ) }) +test_that("extract week from timestamp", { + compare_dplyr_binding( + .input %>% + mutate(x = week(datetime)) %>% + collect(), + test_df + ) +}) + test_that("extract day from timestamp", { compare_dplyr_binding( .input %>% @@ -529,6 +538,15 @@ test_that("extract epiweek from date", { ) }) +test_that("extract week from date", { + compare_dplyr_binding( + .input %>% + mutate(x = week(date)) %>% + collect(), + test_df + ) +}) + test_that("extract month from date", { compare_dplyr_binding( .input %>%