From df230a5c06256eec6596f84478020d807078876e Mon Sep 17 00:00:00 2001 From: Alenka Frim Date: Mon, 11 Apr 2022 12:14:25 +0200 Subject: [PATCH 01/23] Add implementation for dseconds, dmilliseconds, dmicroseconds, dnanoseconds --- r/NEWS.md | 2 + r/R/dplyr-funcs-datetime.R | 18 +++++++ r/tests/testthat/test-dplyr-funcs-datetime.R | 50 ++++++++++++++++++++ 3 files changed, 70 insertions(+) diff --git a/r/NEWS.md b/r/NEWS.md index 9083249a99b..5d16f6e2ec4 100644 --- a/r/NEWS.md +++ b/r/NEWS.md @@ -25,6 +25,8 @@ * Added `make_date()` & `make_datetime()` + `ISOdatetime()` & `ISOdate()` to create date-times from numeric representations. * Added `decimal_date()` and `date_decimal()` * Added `make_difftime()` (duration constructor) + * `make_date()` & `make_datetime()` + `ISOdatetime()` & `ISOdate()` to create date-times from numeric representations. + * duration helper functions: `dyears()`, `dmonths()`, `dweeks()`, `ddays()`, `dhours()`, `dminutes()`, `dseconds()`, `dmilliseconds()`, `dmicroseconds()`, `dnanoseconds()`. * date-time functionality: * Added `difftime` and `as.difftime()` * Added `as.Date()` to convert to date diff --git a/r/R/dplyr-funcs-datetime.R b/r/R/dplyr-funcs-datetime.R index 7657a79271b..c301d09f4b5 100644 --- a/r/R/dplyr-funcs-datetime.R +++ b/r/R/dplyr-funcs-datetime.R @@ -350,6 +350,24 @@ register_bindings_duration <- function() { delta <- build_expr("floor", seconds * fraction) delta <- delta$cast(int64()) start + delta$cast(duration("s")) + register_binding("dseconds", function(x = 1) { + dseconds_int64 <- Expression$create("cast", x, options = cast_options(to_type = int64())) + build_expr("cast", dseconds_int64, options = list(to_type = duration(unit = "s"))) + }) + register_binding("dmilliseconds", function(x = 1) { + dmilliseconds_int64 <- Expression$create("cast", x, options = cast_options(to_type = int64())) + build_expr("cast", dmilliseconds_int64, options = list(to_type = duration(unit = "ms"))) + }) + register_binding("dmicroseconds", function(x = 1) { + dmicroseconds_int64 <- Expression$create("cast", x, options = cast_options(to_type = int64())) + build_expr("cast", dmicroseconds_int64, options = list(to_type = duration(unit = "us"))) + }) + register_binding("dnanoseconds", function(x = 1) { + dnanoseconds_int64 <- Expression$create("cast", x, options = cast_options(to_type = int64())) + build_expr("cast", dnanoseconds_int64, options = list(to_type = duration(unit = "ns"))) + }) + register_binding("dpicoseconds", function(x = 1) { + arrow_not_supported("Duration in picoseconds.") }) } diff --git a/r/tests/testthat/test-dplyr-funcs-datetime.R b/r/tests/testthat/test-dplyr-funcs-datetime.R index b1ff505004b..b718c39cfca 100644 --- a/r/tests/testthat/test-dplyr-funcs-datetime.R +++ b/r/tests/testthat/test-dplyr-funcs-datetime.R @@ -1305,6 +1305,56 @@ test_that("dminutes, dhours, ddays, dweeks, dmonths, dyears", { ) }) +test_that("dseconds, dmilliseconds, dmicroseconds, dnanoseconds, dpicoseconds", { + example_d <- tibble(x = c(1:10, NA)) + date_to_add <- ymd("2009-08-03", tz = "America/Chicago") + + compare_dplyr_binding( + .input %>% + mutate( + dseconds = dseconds(x), + dmilliseconds = dmilliseconds(x), + dmicroseconds = dmicroseconds(x), + dnanoseconds = dnanoseconds(x), + ) %>% + collect(), + example_d, + ignore_attr = TRUE + ) + + compare_dplyr_binding( + .input %>% + mutate( + dseconds = dseconds(x), + dmicroseconds = dmicroseconds(x), + new_date_1 = date_to_add + dseconds, + new_date_2 = date_to_add + dseconds - dmicroseconds, + new_duration = dseconds - dmicroseconds + ) %>% + collect(), + example_d, + ignore_attr = TRUE + ) + + compare_dplyr_binding( + .input %>% + mutate( + r_obj_dseconds = dseconds(1), + r_obj_dmilliseconds = dmilliseconds(2), + r_obj_dmicroseconds = dmicroseconds(3), + r_obj_dnanoseconds = dnanoseconds(4) + ) %>% + collect(), + tibble(), + ignore_attr = TRUE + ) + + expect_error( + call_binding("dpicoseconds"), + "Duration in picoseconds not supported in Arrow" + ) +}) + test_that("make_difftime()", { test_df <- tibble( seconds = c(3, 4, 5, 6), From 1dc35c66c660b850bb3453e31173b9dcb1d696aa Mon Sep 17 00:00:00 2001 From: Alenka Frim Date: Tue, 12 Apr 2022 08:08:58 +0200 Subject: [PATCH 02/23] Correct test for dpicoseconds --- r/R/dplyr-funcs-datetime.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/r/R/dplyr-funcs-datetime.R b/r/R/dplyr-funcs-datetime.R index c301d09f4b5..d4030adae82 100644 --- a/r/R/dplyr-funcs-datetime.R +++ b/r/R/dplyr-funcs-datetime.R @@ -350,6 +350,8 @@ register_bindings_duration <- function() { delta <- build_expr("floor", seconds * fraction) delta <- delta$cast(int64()) start + delta$cast(duration("s")) + }) + } register_binding("dseconds", function(x = 1) { dseconds_int64 <- Expression$create("cast", x, options = cast_options(to_type = int64())) build_expr("cast", dseconds_int64, options = list(to_type = duration(unit = "s"))) From 0ca4d80d3c3bd86293acc81eaa6e221877d0f87a Mon Sep 17 00:00:00 2001 From: Alenka Frim Date: Tue, 12 Apr 2022 13:11:13 +0200 Subject: [PATCH 03/23] Add a check for argument not an Expression and amend the tests --- r/R/dplyr-funcs-datetime.R | 51 +++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/r/R/dplyr-funcs-datetime.R b/r/R/dplyr-funcs-datetime.R index d4030adae82..3ecf854f14c 100644 --- a/r/R/dplyr-funcs-datetime.R +++ b/r/R/dplyr-funcs-datetime.R @@ -323,6 +323,37 @@ register_bindings_duration <- function() { build_expr("cast", x, options = cast_options(to_type = duration(unit = "s"))) }) + register_binding("dseconds", function(x = 1) { + if (!inherits(x, "Expression")) { + x <- Expression$scalar(x) + } + dseconds_int64 <- Expression$create("cast", x, options = cast_options(to_type = int64())) + build_expr("cast", dseconds_int64, options = list(to_type = duration(unit = "s"))) + }) + register_binding("dmilliseconds", function(x = 1) { + if (!inherits(x, "Expression")) { + x <- Expression$scalar(x) + } + dmilliseconds_int64 <- Expression$create("cast", x, options = cast_options(to_type = int64())) + build_expr("cast", dmilliseconds_int64, options = list(to_type = duration(unit = "ms"))) + }) + register_binding("dmicroseconds", function(x = 1) { + if (!inherits(x, "Expression")) { + x <- Expression$scalar(x) + } + dmicroseconds_int64 <- Expression$create("cast", x, options = cast_options(to_type = int64())) + build_expr("cast", dmicroseconds_int64, options = list(to_type = duration(unit = "us"))) + }) + register_binding("dnanoseconds", function(x = 1) { + if (!inherits(x, "Expression")) { + x <- Expression$scalar(x) + } + dnanoseconds_int64 <- Expression$create("cast", x, options = cast_options(to_type = int64())) + build_expr("cast", dnanoseconds_int64, options = list(to_type = duration(unit = "ns"))) + }) + register_binding("dpicoseconds", function(x = 1) { + abort("Duration in picoseconds not supported in Arrow.") + }) register_binding("decimal_date", function(date) { y <- build_expr("year", date) start <- call_binding("make_datetime", year = y, tz = "UTC") @@ -350,26 +381,6 @@ register_bindings_duration <- function() { delta <- build_expr("floor", seconds * fraction) delta <- delta$cast(int64()) start + delta$cast(duration("s")) - }) - } - register_binding("dseconds", function(x = 1) { - dseconds_int64 <- Expression$create("cast", x, options = cast_options(to_type = int64())) - build_expr("cast", dseconds_int64, options = list(to_type = duration(unit = "s"))) - }) - register_binding("dmilliseconds", function(x = 1) { - dmilliseconds_int64 <- Expression$create("cast", x, options = cast_options(to_type = int64())) - build_expr("cast", dmilliseconds_int64, options = list(to_type = duration(unit = "ms"))) - }) - register_binding("dmicroseconds", function(x = 1) { - dmicroseconds_int64 <- Expression$create("cast", x, options = cast_options(to_type = int64())) - build_expr("cast", dmicroseconds_int64, options = list(to_type = duration(unit = "us"))) - }) - register_binding("dnanoseconds", function(x = 1) { - dnanoseconds_int64 <- Expression$create("cast", x, options = cast_options(to_type = int64())) - build_expr("cast", dnanoseconds_int64, options = list(to_type = duration(unit = "ns"))) - }) - register_binding("dpicoseconds", function(x = 1) { - arrow_not_supported("Duration in picoseconds.") }) } From b7de259c2cb69a64b3fe77bdf1f9b3ad1808a42e Mon Sep 17 00:00:00 2001 From: Alenka Frim Date: Thu, 14 Apr 2022 10:18:32 +0200 Subject: [PATCH 04/23] Move the duration helpers into register_bindings_duration_helpers --- r/R/dplyr-funcs-datetime.R | 59 ++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/r/R/dplyr-funcs-datetime.R b/r/R/dplyr-funcs-datetime.R index 3ecf854f14c..3e93f154dbf 100644 --- a/r/R/dplyr-funcs-datetime.R +++ b/r/R/dplyr-funcs-datetime.R @@ -323,6 +323,37 @@ register_bindings_duration <- function() { build_expr("cast", x, options = cast_options(to_type = duration(unit = "s"))) }) + register_binding("decimal_date", function(date) { + y <- build_expr("year", date) + start <- call_binding("make_datetime", year = y, tz = "UTC") + sofar <- call_binding("difftime", date, start, units = "secs") + total <- call_binding( + "if_else", + build_expr("is_leap_year", date), + Expression$scalar(31622400L), # number of seconds in a leap year (366 days) + Expression$scalar(31536000L) # number of seconds in a regular year (365 days) + ) + y + sofar$cast(int64()) / total + }) + register_binding("date_decimal", function(decimal, tz = "UTC") { + y <- build_expr("floor", decimal) + + start <- call_binding("make_datetime", year = y, tz = tz) + seconds <- call_binding( + "if_else", + build_expr("is_leap_year", start), + Expression$scalar(31622400L), # number of seconds in a leap year (366 days) + Expression$scalar(31536000L) # number of seconds in a regular year (365 days) + ) + + fraction <- decimal - y + delta <- build_expr("floor", seconds * fraction) + delta <- delta$cast(int64()) + start + delta$cast(duration("s")) + }) +} + +register_bindings_duration_helpers <- function() { register_binding("dseconds", function(x = 1) { if (!inherits(x, "Expression")) { x <- Expression$scalar(x) @@ -354,34 +385,6 @@ register_bindings_duration <- function() { register_binding("dpicoseconds", function(x = 1) { abort("Duration in picoseconds not supported in Arrow.") }) - register_binding("decimal_date", function(date) { - y <- build_expr("year", date) - start <- call_binding("make_datetime", year = y, tz = "UTC") - sofar <- call_binding("difftime", date, start, units = "secs") - total <- call_binding( - "if_else", - build_expr("is_leap_year", date), - Expression$scalar(31622400L), # number of seconds in a leap year (366 days) - Expression$scalar(31536000L) # number of seconds in a regular year (365 days) - ) - y + sofar$cast(int64()) / total - }) - register_binding("date_decimal", function(decimal, tz = "UTC") { - y <- build_expr("floor", decimal) - - start <- call_binding("make_datetime", year = y, tz = tz) - seconds <- call_binding( - "if_else", - build_expr("is_leap_year", start), - Expression$scalar(31622400L), # number of seconds in a leap year (366 days) - Expression$scalar(31536000L) # number of seconds in a regular year (365 days) - ) - - fraction <- decimal - y - delta <- build_expr("floor", seconds * fraction) - delta <- delta$cast(int64()) - start + delta$cast(duration("s")) - }) } register_bindings_difftime_constructors <- function() { From 5bd6a5e556f93d6e769cd91999844fe1b13c6c56 Mon Sep 17 00:00:00 2001 From: Alenka Frim Date: Thu, 14 Apr 2022 10:26:23 +0200 Subject: [PATCH 05/23] Replace Expression() with build_expr() --- r/R/dplyr-funcs-datetime.R | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/r/R/dplyr-funcs-datetime.R b/r/R/dplyr-funcs-datetime.R index 3e93f154dbf..e492c83ef5b 100644 --- a/r/R/dplyr-funcs-datetime.R +++ b/r/R/dplyr-funcs-datetime.R @@ -355,32 +355,20 @@ register_bindings_duration <- function() { register_bindings_duration_helpers <- function() { register_binding("dseconds", function(x = 1) { - if (!inherits(x, "Expression")) { - x <- Expression$scalar(x) - } - dseconds_int64 <- Expression$create("cast", x, options = cast_options(to_type = int64())) - build_expr("cast", dseconds_int64, options = list(to_type = duration(unit = "s"))) + x <- build_expr("cast", x, options = cast_options(to_type = int64())) + x$cast(duration("s")) }) register_binding("dmilliseconds", function(x = 1) { - if (!inherits(x, "Expression")) { - x <- Expression$scalar(x) - } - dmilliseconds_int64 <- Expression$create("cast", x, options = cast_options(to_type = int64())) - build_expr("cast", dmilliseconds_int64, options = list(to_type = duration(unit = "ms"))) + x <- build_expr("cast", x, options = cast_options(to_type = int64())) + x$cast(duration("ms")) }) register_binding("dmicroseconds", function(x = 1) { - if (!inherits(x, "Expression")) { - x <- Expression$scalar(x) - } - dmicroseconds_int64 <- Expression$create("cast", x, options = cast_options(to_type = int64())) - build_expr("cast", dmicroseconds_int64, options = list(to_type = duration(unit = "us"))) + x <- build_expr("cast", x, options = cast_options(to_type = int64())) + x$cast(duration("us")) }) register_binding("dnanoseconds", function(x = 1) { - if (!inherits(x, "Expression")) { - x <- Expression$scalar(x) - } - dnanoseconds_int64 <- Expression$create("cast", x, options = cast_options(to_type = int64())) - build_expr("cast", dnanoseconds_int64, options = list(to_type = duration(unit = "ns"))) + x <- build_expr("cast", x, options = cast_options(to_type = int64())) + x$cast(duration("ns")) }) register_binding("dpicoseconds", function(x = 1) { abort("Duration in picoseconds not supported in Arrow.") From d139be722f9f083af098f5e5b01ebfeb81756017 Mon Sep 17 00:00:00 2001 From: Alenka Frim Date: Thu, 14 Apr 2022 10:47:26 +0200 Subject: [PATCH 06/23] Add a helper function to avoid repetition --- r/R/dplyr-funcs-datetime.R | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/r/R/dplyr-funcs-datetime.R b/r/R/dplyr-funcs-datetime.R index e492c83ef5b..82426a333f0 100644 --- a/r/R/dplyr-funcs-datetime.R +++ b/r/R/dplyr-funcs-datetime.R @@ -354,21 +354,21 @@ register_bindings_duration <- function() { } register_bindings_duration_helpers <- function() { - register_binding("dseconds", function(x = 1) { + make_duration <- function(x, unit) { x <- build_expr("cast", x, options = cast_options(to_type = int64())) - x$cast(duration("s")) + x$cast(duration(unit)) + } + register_binding("dseconds", function(x = 1) { + make_duration(x, "s") }) register_binding("dmilliseconds", function(x = 1) { - x <- build_expr("cast", x, options = cast_options(to_type = int64())) - x$cast(duration("ms")) + make_duration(x, "ms") }) register_binding("dmicroseconds", function(x = 1) { - x <- build_expr("cast", x, options = cast_options(to_type = int64())) - x$cast(duration("us")) + make_duration(x, "us") }) register_binding("dnanoseconds", function(x = 1) { - x <- build_expr("cast", x, options = cast_options(to_type = int64())) - x$cast(duration("ns")) + make_duration(x, "ns") }) register_binding("dpicoseconds", function(x = 1) { abort("Duration in picoseconds not supported in Arrow.") From f0678b1ef79cb8b69ef8074bfcd9d8c07b22fea6 Mon Sep 17 00:00:00 2001 From: Alenka Frim Date: Thu, 14 Apr 2022 11:10:40 +0200 Subject: [PATCH 07/23] Make make_duration a standalone function --- r/R/dplyr-funcs-datetime.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/r/R/dplyr-funcs-datetime.R b/r/R/dplyr-funcs-datetime.R index 82426a333f0..932bdc11ca9 100644 --- a/r/R/dplyr-funcs-datetime.R +++ b/r/R/dplyr-funcs-datetime.R @@ -353,11 +353,11 @@ register_bindings_duration <- function() { }) } +make_duration <- function(x, unit) { + x <- build_expr("cast", x, options = cast_options(to_type = int64())) + x$cast(duration(unit)) +} register_bindings_duration_helpers <- function() { - make_duration <- function(x, unit) { - x <- build_expr("cast", x, options = cast_options(to_type = int64())) - x$cast(duration(unit)) - } register_binding("dseconds", function(x = 1) { make_duration(x, "s") }) From 26a30c51fd85245746dbeb9b30abe229a58902c0 Mon Sep 17 00:00:00 2001 From: Alenka Frim Date: Fri, 15 Apr 2022 06:34:10 +0200 Subject: [PATCH 08/23] Correct two typos left from the conflict merge --- r/R/dplyr-funcs-datetime.R | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/r/R/dplyr-funcs-datetime.R b/r/R/dplyr-funcs-datetime.R index 932bdc11ca9..4a4fdd00bf8 100644 --- a/r/R/dplyr-funcs-datetime.R +++ b/r/R/dplyr-funcs-datetime.R @@ -427,6 +427,24 @@ register_bindings_duration_helpers <- function() { }) register_binding("dyears", function(x = 1) { make_duration(x * 31557600, "s") +<<<<<<< HEAD +======= + }) + register_binding("dseconds", function(x = 1) { + make_duration(x, "s") + }) + register_binding("dmilliseconds", function(x = 1) { + make_duration(x, "ms") + }) + register_binding("dmicroseconds", function(x = 1) { + make_duration(x, "us") + }) + register_binding("dnanoseconds", function(x = 1) { + make_duration(x, "ns") + }) + register_binding("dpicoseconds", function(x = 1) { + abort("Duration in picoseconds not supported in Arrow.") +>>>>>>> 3651fb81a (Correct two typos left from the conflict merge) }) } From aa3d54fa6ec488f30a150ca845519f88c20ee636 Mon Sep 17 00:00:00 2001 From: Alenka Frim Date: Wed, 20 Apr 2022 14:15:22 +0200 Subject: [PATCH 09/23] testing --- r/R/dplyr-funcs-datetime.R | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/r/R/dplyr-funcs-datetime.R b/r/R/dplyr-funcs-datetime.R index 4a4fdd00bf8..407411e189b 100644 --- a/r/R/dplyr-funcs-datetime.R +++ b/r/R/dplyr-funcs-datetime.R @@ -353,28 +353,6 @@ register_bindings_duration <- function() { }) } -make_duration <- function(x, unit) { - x <- build_expr("cast", x, options = cast_options(to_type = int64())) - x$cast(duration(unit)) -} -register_bindings_duration_helpers <- function() { - register_binding("dseconds", function(x = 1) { - make_duration(x, "s") - }) - register_binding("dmilliseconds", function(x = 1) { - make_duration(x, "ms") - }) - register_binding("dmicroseconds", function(x = 1) { - make_duration(x, "us") - }) - register_binding("dnanoseconds", function(x = 1) { - make_duration(x, "ns") - }) - register_binding("dpicoseconds", function(x = 1) { - abort("Duration in picoseconds not supported in Arrow.") - }) -} - register_bindings_difftime_constructors <- function() { register_binding("make_difftime", function(num = NULL, units = "secs", @@ -427,8 +405,6 @@ register_bindings_duration_helpers <- function() { }) register_binding("dyears", function(x = 1) { make_duration(x * 31557600, "s") -<<<<<<< HEAD -======= }) register_binding("dseconds", function(x = 1) { make_duration(x, "s") @@ -444,7 +420,6 @@ register_bindings_duration_helpers <- function() { }) register_binding("dpicoseconds", function(x = 1) { abort("Duration in picoseconds not supported in Arrow.") ->>>>>>> 3651fb81a (Correct two typos left from the conflict merge) }) } From 10ce36ba59baa42e562dd8f6abad9248d2cd1611 Mon Sep 17 00:00:00 2001 From: Alenka Frim Date: Mon, 11 Apr 2022 12:14:25 +0200 Subject: [PATCH 10/23] Add implementation for dseconds, dmilliseconds, dmicroseconds, dnanoseconds --- r/R/dplyr-funcs-datetime.R | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/r/R/dplyr-funcs-datetime.R b/r/R/dplyr-funcs-datetime.R index 407411e189b..444de10309b 100644 --- a/r/R/dplyr-funcs-datetime.R +++ b/r/R/dplyr-funcs-datetime.R @@ -350,6 +350,24 @@ register_bindings_duration <- function() { delta <- build_expr("floor", seconds * fraction) delta <- delta$cast(int64()) start + delta$cast(duration("s")) + register_binding("dseconds", function(x = 1) { + dseconds_int64 <- Expression$create("cast", x, options = cast_options(to_type = int64())) + build_expr("cast", dseconds_int64, options = list(to_type = duration(unit = "s"))) + }) + register_binding("dmilliseconds", function(x = 1) { + dmilliseconds_int64 <- Expression$create("cast", x, options = cast_options(to_type = int64())) + build_expr("cast", dmilliseconds_int64, options = list(to_type = duration(unit = "ms"))) + }) + register_binding("dmicroseconds", function(x = 1) { + dmicroseconds_int64 <- Expression$create("cast", x, options = cast_options(to_type = int64())) + build_expr("cast", dmicroseconds_int64, options = list(to_type = duration(unit = "us"))) + }) + register_binding("dnanoseconds", function(x = 1) { + dnanoseconds_int64 <- Expression$create("cast", x, options = cast_options(to_type = int64())) + build_expr("cast", dnanoseconds_int64, options = list(to_type = duration(unit = "ns"))) + }) + register_binding("dpicoseconds", function(x = 1) { + arrow_not_supported("Duration in picoseconds.") }) } From 9aca24d5bcfb49e61c68d433104c8d39e8146ef7 Mon Sep 17 00:00:00 2001 From: Alenka Frim Date: Tue, 12 Apr 2022 08:08:58 +0200 Subject: [PATCH 11/23] Correct test for dpicoseconds --- r/R/dplyr-funcs-datetime.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/r/R/dplyr-funcs-datetime.R b/r/R/dplyr-funcs-datetime.R index 444de10309b..c6f01415861 100644 --- a/r/R/dplyr-funcs-datetime.R +++ b/r/R/dplyr-funcs-datetime.R @@ -350,6 +350,8 @@ register_bindings_duration <- function() { delta <- build_expr("floor", seconds * fraction) delta <- delta$cast(int64()) start + delta$cast(duration("s")) + }) + } register_binding("dseconds", function(x = 1) { dseconds_int64 <- Expression$create("cast", x, options = cast_options(to_type = int64())) build_expr("cast", dseconds_int64, options = list(to_type = duration(unit = "s"))) From 3991f5c9531328a29e210438e435c8dcda8af0c6 Mon Sep 17 00:00:00 2001 From: Alenka Frim Date: Tue, 12 Apr 2022 13:11:13 +0200 Subject: [PATCH 12/23] Add a check for argument not an Expression and amend the tests --- r/R/dplyr-funcs-datetime.R | 51 +++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/r/R/dplyr-funcs-datetime.R b/r/R/dplyr-funcs-datetime.R index c6f01415861..80096828f8c 100644 --- a/r/R/dplyr-funcs-datetime.R +++ b/r/R/dplyr-funcs-datetime.R @@ -323,6 +323,37 @@ register_bindings_duration <- function() { build_expr("cast", x, options = cast_options(to_type = duration(unit = "s"))) }) + register_binding("dseconds", function(x = 1) { + if (!inherits(x, "Expression")) { + x <- Expression$scalar(x) + } + dseconds_int64 <- Expression$create("cast", x, options = cast_options(to_type = int64())) + build_expr("cast", dseconds_int64, options = list(to_type = duration(unit = "s"))) + }) + register_binding("dmilliseconds", function(x = 1) { + if (!inherits(x, "Expression")) { + x <- Expression$scalar(x) + } + dmilliseconds_int64 <- Expression$create("cast", x, options = cast_options(to_type = int64())) + build_expr("cast", dmilliseconds_int64, options = list(to_type = duration(unit = "ms"))) + }) + register_binding("dmicroseconds", function(x = 1) { + if (!inherits(x, "Expression")) { + x <- Expression$scalar(x) + } + dmicroseconds_int64 <- Expression$create("cast", x, options = cast_options(to_type = int64())) + build_expr("cast", dmicroseconds_int64, options = list(to_type = duration(unit = "us"))) + }) + register_binding("dnanoseconds", function(x = 1) { + if (!inherits(x, "Expression")) { + x <- Expression$scalar(x) + } + dnanoseconds_int64 <- Expression$create("cast", x, options = cast_options(to_type = int64())) + build_expr("cast", dnanoseconds_int64, options = list(to_type = duration(unit = "ns"))) + }) + register_binding("dpicoseconds", function(x = 1) { + abort("Duration in picoseconds not supported in Arrow.") + }) register_binding("decimal_date", function(date) { y <- build_expr("year", date) start <- call_binding("make_datetime", year = y, tz = "UTC") @@ -350,26 +381,6 @@ register_bindings_duration <- function() { delta <- build_expr("floor", seconds * fraction) delta <- delta$cast(int64()) start + delta$cast(duration("s")) - }) - } - register_binding("dseconds", function(x = 1) { - dseconds_int64 <- Expression$create("cast", x, options = cast_options(to_type = int64())) - build_expr("cast", dseconds_int64, options = list(to_type = duration(unit = "s"))) - }) - register_binding("dmilliseconds", function(x = 1) { - dmilliseconds_int64 <- Expression$create("cast", x, options = cast_options(to_type = int64())) - build_expr("cast", dmilliseconds_int64, options = list(to_type = duration(unit = "ms"))) - }) - register_binding("dmicroseconds", function(x = 1) { - dmicroseconds_int64 <- Expression$create("cast", x, options = cast_options(to_type = int64())) - build_expr("cast", dmicroseconds_int64, options = list(to_type = duration(unit = "us"))) - }) - register_binding("dnanoseconds", function(x = 1) { - dnanoseconds_int64 <- Expression$create("cast", x, options = cast_options(to_type = int64())) - build_expr("cast", dnanoseconds_int64, options = list(to_type = duration(unit = "ns"))) - }) - register_binding("dpicoseconds", function(x = 1) { - arrow_not_supported("Duration in picoseconds.") }) } From 9a6c5f7eba83a92f39daea049971b92db1451c32 Mon Sep 17 00:00:00 2001 From: Alenka Frim Date: Thu, 14 Apr 2022 10:18:32 +0200 Subject: [PATCH 13/23] Move the duration helpers into register_bindings_duration_helpers --- r/R/dplyr-funcs-datetime.R | 59 ++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/r/R/dplyr-funcs-datetime.R b/r/R/dplyr-funcs-datetime.R index 80096828f8c..127347b452d 100644 --- a/r/R/dplyr-funcs-datetime.R +++ b/r/R/dplyr-funcs-datetime.R @@ -323,6 +323,37 @@ register_bindings_duration <- function() { build_expr("cast", x, options = cast_options(to_type = duration(unit = "s"))) }) + register_binding("decimal_date", function(date) { + y <- build_expr("year", date) + start <- call_binding("make_datetime", year = y, tz = "UTC") + sofar <- call_binding("difftime", date, start, units = "secs") + total <- call_binding( + "if_else", + build_expr("is_leap_year", date), + Expression$scalar(31622400L), # number of seconds in a leap year (366 days) + Expression$scalar(31536000L) # number of seconds in a regular year (365 days) + ) + y + sofar$cast(int64()) / total + }) + register_binding("date_decimal", function(decimal, tz = "UTC") { + y <- build_expr("floor", decimal) + + start <- call_binding("make_datetime", year = y, tz = tz) + seconds <- call_binding( + "if_else", + build_expr("is_leap_year", start), + Expression$scalar(31622400L), # number of seconds in a leap year (366 days) + Expression$scalar(31536000L) # number of seconds in a regular year (365 days) + ) + + fraction <- decimal - y + delta <- build_expr("floor", seconds * fraction) + delta <- delta$cast(int64()) + start + delta$cast(duration("s")) + }) +} + +register_bindings_duration_helpers <- function() { register_binding("dseconds", function(x = 1) { if (!inherits(x, "Expression")) { x <- Expression$scalar(x) @@ -354,34 +385,6 @@ register_bindings_duration <- function() { register_binding("dpicoseconds", function(x = 1) { abort("Duration in picoseconds not supported in Arrow.") }) - register_binding("decimal_date", function(date) { - y <- build_expr("year", date) - start <- call_binding("make_datetime", year = y, tz = "UTC") - sofar <- call_binding("difftime", date, start, units = "secs") - total <- call_binding( - "if_else", - build_expr("is_leap_year", date), - Expression$scalar(31622400L), # number of seconds in a leap year (366 days) - Expression$scalar(31536000L) # number of seconds in a regular year (365 days) - ) - y + sofar$cast(int64()) / total - }) - register_binding("date_decimal", function(decimal, tz = "UTC") { - y <- build_expr("floor", decimal) - - start <- call_binding("make_datetime", year = y, tz = tz) - seconds <- call_binding( - "if_else", - build_expr("is_leap_year", start), - Expression$scalar(31622400L), # number of seconds in a leap year (366 days) - Expression$scalar(31536000L) # number of seconds in a regular year (365 days) - ) - - fraction <- decimal - y - delta <- build_expr("floor", seconds * fraction) - delta <- delta$cast(int64()) - start + delta$cast(duration("s")) - }) } register_bindings_difftime_constructors <- function() { From 115c6c49918b47bf1da10478beb6fe65527fa29d Mon Sep 17 00:00:00 2001 From: Alenka Frim Date: Thu, 14 Apr 2022 10:26:23 +0200 Subject: [PATCH 14/23] Replace Expression() with build_expr() --- r/R/dplyr-funcs-datetime.R | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/r/R/dplyr-funcs-datetime.R b/r/R/dplyr-funcs-datetime.R index 127347b452d..f4310b0da83 100644 --- a/r/R/dplyr-funcs-datetime.R +++ b/r/R/dplyr-funcs-datetime.R @@ -355,32 +355,20 @@ register_bindings_duration <- function() { register_bindings_duration_helpers <- function() { register_binding("dseconds", function(x = 1) { - if (!inherits(x, "Expression")) { - x <- Expression$scalar(x) - } - dseconds_int64 <- Expression$create("cast", x, options = cast_options(to_type = int64())) - build_expr("cast", dseconds_int64, options = list(to_type = duration(unit = "s"))) + x <- build_expr("cast", x, options = cast_options(to_type = int64())) + x$cast(duration("s")) }) register_binding("dmilliseconds", function(x = 1) { - if (!inherits(x, "Expression")) { - x <- Expression$scalar(x) - } - dmilliseconds_int64 <- Expression$create("cast", x, options = cast_options(to_type = int64())) - build_expr("cast", dmilliseconds_int64, options = list(to_type = duration(unit = "ms"))) + x <- build_expr("cast", x, options = cast_options(to_type = int64())) + x$cast(duration("ms")) }) register_binding("dmicroseconds", function(x = 1) { - if (!inherits(x, "Expression")) { - x <- Expression$scalar(x) - } - dmicroseconds_int64 <- Expression$create("cast", x, options = cast_options(to_type = int64())) - build_expr("cast", dmicroseconds_int64, options = list(to_type = duration(unit = "us"))) + x <- build_expr("cast", x, options = cast_options(to_type = int64())) + x$cast(duration("us")) }) register_binding("dnanoseconds", function(x = 1) { - if (!inherits(x, "Expression")) { - x <- Expression$scalar(x) - } - dnanoseconds_int64 <- Expression$create("cast", x, options = cast_options(to_type = int64())) - build_expr("cast", dnanoseconds_int64, options = list(to_type = duration(unit = "ns"))) + x <- build_expr("cast", x, options = cast_options(to_type = int64())) + x$cast(duration("ns")) }) register_binding("dpicoseconds", function(x = 1) { abort("Duration in picoseconds not supported in Arrow.") From eda6b8c88b958b12989feb1254441cdb0fa6ea62 Mon Sep 17 00:00:00 2001 From: Alenka Frim Date: Thu, 14 Apr 2022 10:47:26 +0200 Subject: [PATCH 15/23] Add a helper function to avoid repetition --- r/R/dplyr-funcs-datetime.R | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/r/R/dplyr-funcs-datetime.R b/r/R/dplyr-funcs-datetime.R index f4310b0da83..3597bbb9566 100644 --- a/r/R/dplyr-funcs-datetime.R +++ b/r/R/dplyr-funcs-datetime.R @@ -354,21 +354,21 @@ register_bindings_duration <- function() { } register_bindings_duration_helpers <- function() { - register_binding("dseconds", function(x = 1) { + make_duration <- function(x, unit) { x <- build_expr("cast", x, options = cast_options(to_type = int64())) - x$cast(duration("s")) + x$cast(duration(unit)) + } + register_binding("dseconds", function(x = 1) { + make_duration(x, "s") }) register_binding("dmilliseconds", function(x = 1) { - x <- build_expr("cast", x, options = cast_options(to_type = int64())) - x$cast(duration("ms")) + make_duration(x, "ms") }) register_binding("dmicroseconds", function(x = 1) { - x <- build_expr("cast", x, options = cast_options(to_type = int64())) - x$cast(duration("us")) + make_duration(x, "us") }) register_binding("dnanoseconds", function(x = 1) { - x <- build_expr("cast", x, options = cast_options(to_type = int64())) - x$cast(duration("ns")) + make_duration(x, "ns") }) register_binding("dpicoseconds", function(x = 1) { abort("Duration in picoseconds not supported in Arrow.") From 13e11a7bcc7e9f6eb77838ff2522529d312122c4 Mon Sep 17 00:00:00 2001 From: Alenka Frim Date: Thu, 14 Apr 2022 11:10:40 +0200 Subject: [PATCH 16/23] Make make_duration a standalone function --- r/R/dplyr-funcs-datetime.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/r/R/dplyr-funcs-datetime.R b/r/R/dplyr-funcs-datetime.R index 3597bbb9566..bf0ea4ef96c 100644 --- a/r/R/dplyr-funcs-datetime.R +++ b/r/R/dplyr-funcs-datetime.R @@ -353,11 +353,11 @@ register_bindings_duration <- function() { }) } +make_duration <- function(x, unit) { + x <- build_expr("cast", x, options = cast_options(to_type = int64())) + x$cast(duration(unit)) +} register_bindings_duration_helpers <- function() { - make_duration <- function(x, unit) { - x <- build_expr("cast", x, options = cast_options(to_type = int64())) - x$cast(duration(unit)) - } register_binding("dseconds", function(x = 1) { make_duration(x, "s") }) From 23ca3705f8e817ef0aff584c5c408baf3dc502ea Mon Sep 17 00:00:00 2001 From: Alenka Frim Date: Wed, 20 Apr 2022 14:15:22 +0200 Subject: [PATCH 17/23] testing --- r/R/dplyr-funcs-datetime.R | 80 +++++++++++++------------------------- 1 file changed, 28 insertions(+), 52 deletions(-) diff --git a/r/R/dplyr-funcs-datetime.R b/r/R/dplyr-funcs-datetime.R index bf0ea4ef96c..0ae7dabc4b7 100644 --- a/r/R/dplyr-funcs-datetime.R +++ b/r/R/dplyr-funcs-datetime.R @@ -353,23 +353,39 @@ register_bindings_duration <- function() { }) } +.helpers_function_map <- list( + "dminutes" = c(60, "s"), + "dhours" = c(3600, "s"), + "ddays" = c(86400, "s"), + "dweeks" = c(604800, "s"), + "dmonths" = c(2629800, "s"), + "ydyears" = c(31557600, "s"), + "dseconds" = c(1, "s"), + "dmilliseconds" = c(1, "ms"), + "dmicroseconds" = c(1, "us"), + "dnanoseconds" = c(1, "ns") +) make_duration <- function(x, unit) { x <- build_expr("cast", x, options = cast_options(to_type = int64())) x$cast(duration(unit)) } register_bindings_duration_helpers <- function() { - register_binding("dseconds", function(x = 1) { - make_duration(x, "s") - }) - register_binding("dmilliseconds", function(x = 1) { - make_duration(x, "ms") - }) - register_binding("dmicroseconds", function(x = 1) { - make_duration(x, "us") - }) - register_binding("dnanoseconds", function(x = 1) { - make_duration(x, "ns") - }) + duration_helpers_map_factory <- function(value, unit) { + force(value) + force(unit) + function(x = 1) make_duration(x * value, unit) + } + + for (name in names(.helpers_function_map)){ + register_binding( + name, + duration_helpers_map_factory( + .helpers_function_map[[name]][1], + .helpers_function_map[[name]][2] + ) + ) + } + register_binding("dpicoseconds", function(x = 1) { abort("Duration in picoseconds not supported in Arrow.") }) @@ -405,46 +421,6 @@ register_bindings_difftime_constructors <- function() { }) } -make_duration <- function(x, unit) { - x <- build_expr("cast", x, options = cast_options(to_type = int64())) - x$cast(duration(unit)) -} -register_bindings_duration_helpers <- function() { - register_binding("dminutes", function(x = 1) { - make_duration(x * 60, "s") - }) - register_binding("dhours", function(x = 1) { - make_duration(x * 3600, "s") - }) - register_binding("ddays", function(x = 1) { - make_duration(x * 86400, "s") - }) - register_binding("dweeks", function(x = 1) { - make_duration(x * 604800, "s") - }) - register_binding("dmonths", function(x = 1) { - make_duration(x * 2629800, "s") - }) - register_binding("dyears", function(x = 1) { - make_duration(x * 31557600, "s") - }) - register_binding("dseconds", function(x = 1) { - make_duration(x, "s") - }) - register_binding("dmilliseconds", function(x = 1) { - make_duration(x, "ms") - }) - register_binding("dmicroseconds", function(x = 1) { - make_duration(x, "us") - }) - register_binding("dnanoseconds", function(x = 1) { - make_duration(x, "ns") - }) - register_binding("dpicoseconds", function(x = 1) { - abort("Duration in picoseconds not supported in Arrow.") - }) -} - binding_format_datetime <- function(x, format = "", tz = "", usetz = FALSE) { if (usetz) { format <- paste(format, "%Z") From bef9aa91426773156c3ff60ebc316cc12eb20f58 Mon Sep 17 00:00:00 2001 From: Alenka Frim Date: Wed, 20 Apr 2022 17:55:24 +0200 Subject: [PATCH 18/23] Create map factory for duration helpers --- r/R/dplyr-funcs-datetime.R | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/r/R/dplyr-funcs-datetime.R b/r/R/dplyr-funcs-datetime.R index 0ae7dabc4b7..0d8beb7951d 100644 --- a/r/R/dplyr-funcs-datetime.R +++ b/r/R/dplyr-funcs-datetime.R @@ -354,16 +354,16 @@ register_bindings_duration <- function() { } .helpers_function_map <- list( - "dminutes" = c(60, "s"), - "dhours" = c(3600, "s"), - "ddays" = c(86400, "s"), - "dweeks" = c(604800, "s"), - "dmonths" = c(2629800, "s"), - "ydyears" = c(31557600, "s"), - "dseconds" = c(1, "s"), - "dmilliseconds" = c(1, "ms"), - "dmicroseconds" = c(1, "us"), - "dnanoseconds" = c(1, "ns") + "dminutes" = list(60, "s"), + "dhours" = list(3600, "s"), + "ddays" = list(86400, "s"), + "dweeks" = list(604800, "s"), + "dmonths" = list(2629800, "s"), + "dyears" = list(31557600, "s"), + "dseconds" = list(1, "s"), + "dmilliseconds" = list(1, "ms"), + "dmicroseconds" = list(1, "us"), + "dnanoseconds" = list(1, "ns") ) make_duration <- function(x, unit) { x <- build_expr("cast", x, options = cast_options(to_type = int64())) @@ -380,8 +380,8 @@ register_bindings_duration_helpers <- function() { register_binding( name, duration_helpers_map_factory( - .helpers_function_map[[name]][1], - .helpers_function_map[[name]][2] + .helpers_function_map[[name]][[1]], + .helpers_function_map[[name]][[2]] ) ) } From 17b7fa47211714d94acef56c082b93ce6693c4c9 Mon Sep 17 00:00:00 2001 From: Alenka Frim Date: Thu, 21 Apr 2022 14:14:24 +0200 Subject: [PATCH 19/23] Redo tz change lost in a force-push --- r/tests/testthat/test-dplyr-funcs-datetime.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/r/tests/testthat/test-dplyr-funcs-datetime.R b/r/tests/testthat/test-dplyr-funcs-datetime.R index b718c39cfca..e84d0714136 100644 --- a/r/tests/testthat/test-dplyr-funcs-datetime.R +++ b/r/tests/testthat/test-dplyr-funcs-datetime.R @@ -1258,7 +1258,7 @@ test_that("`decimal_date()` and `date_decimal()`", { test_that("dminutes, dhours, ddays, dweeks, dmonths, dyears", { example_d <- tibble(x = c(1:10, NA)) - date_to_add <- ymd("2009-08-03", tz = "America/Chicago") + date_to_add <- ymd("2009-08-03", tz = "Pacific/Marquesas") compare_dplyr_binding( .input %>% @@ -1307,7 +1307,7 @@ test_that("dminutes, dhours, ddays, dweeks, dmonths, dyears", { test_that("dseconds, dmilliseconds, dmicroseconds, dnanoseconds, dpicoseconds", { example_d <- tibble(x = c(1:10, NA)) - date_to_add <- ymd("2009-08-03", tz = "America/Chicago") + date_to_add <- ymd("2009-08-03", tz = "Pacific/Marquesas") compare_dplyr_binding( .input %>% From 55ab2c722817b322a88b425010d4ab19c3ea1cc6 Mon Sep 17 00:00:00 2001 From: Alenka Frim Date: Thu, 21 Apr 2022 14:22:28 +0200 Subject: [PATCH 20/23] Add a a test to check for error in case of a double --- r/tests/testthat/test-dplyr-funcs-datetime.R | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/r/tests/testthat/test-dplyr-funcs-datetime.R b/r/tests/testthat/test-dplyr-funcs-datetime.R index e84d0714136..7a51ddf9b5f 100644 --- a/r/tests/testthat/test-dplyr-funcs-datetime.R +++ b/r/tests/testthat/test-dplyr-funcs-datetime.R @@ -1303,6 +1303,15 @@ test_that("dminutes, dhours, ddays, dweeks, dmonths, dyears", { tibble(), ignore_attr = TRUE ) + + # double -> duration not supported in Arrow. + # Error is generated in the C++ code + expect_error( + test_df %>% + arrow_table() %>% + mutate(r_obj_dminutes = dminutes(1.12345)) %>% + collect() + ) }) test_that("dseconds, dmilliseconds, dmicroseconds, dnanoseconds, dpicoseconds", { @@ -1353,6 +1362,15 @@ test_that("dseconds, dmilliseconds, dmicroseconds, dnanoseconds, dpicoseconds", call_binding("dpicoseconds"), "Duration in picoseconds not supported in Arrow" ) + + # double -> duration not supported in Arrow. + # Error is generated in the C++ code + expect_error( + test_df %>% + arrow_table() %>% + mutate(r_obj_dseconds = dseconds(1.12345)) %>% + collect() + ) }) test_that("make_difftime()", { From 6e0c9bbba71d155b49c3835a3f685fac3a6b170b Mon Sep 17 00:00:00 2001 From: Alenka Frim Date: Thu, 21 Apr 2022 14:28:09 +0200 Subject: [PATCH 21/23] Correct content in NEWS.md --- r/NEWS.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/r/NEWS.md b/r/NEWS.md index 5d16f6e2ec4..eb5cd9a1554 100644 --- a/r/NEWS.md +++ b/r/NEWS.md @@ -25,8 +25,7 @@ * Added `make_date()` & `make_datetime()` + `ISOdatetime()` & `ISOdate()` to create date-times from numeric representations. * Added `decimal_date()` and `date_decimal()` * Added `make_difftime()` (duration constructor) - * `make_date()` & `make_datetime()` + `ISOdatetime()` & `ISOdate()` to create date-times from numeric representations. - * duration helper functions: `dyears()`, `dmonths()`, `dweeks()`, `ddays()`, `dhours()`, `dminutes()`, `dseconds()`, `dmilliseconds()`, `dmicroseconds()`, `dnanoseconds()`. + * Added duration helper functions: `dyears()`, `dmonths()`, `dweeks()`, `ddays()`, `dhours()`, `dminutes()`, `dseconds()`, `dmilliseconds()`, `dmicroseconds()`, `dnanoseconds()`. * date-time functionality: * Added `difftime` and `as.difftime()` * Added `as.Date()` to convert to date From 00a5eef0282719d6a1860a8c3e2d73a8fbd5c8f1 Mon Sep 17 00:00:00 2001 From: Alenka Frim Date: Thu, 21 Apr 2022 17:23:18 +0200 Subject: [PATCH 22/23] Fix typo --- r/R/dplyr-funcs-datetime.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r/R/dplyr-funcs-datetime.R b/r/R/dplyr-funcs-datetime.R index 0d8beb7951d..a674a6402bd 100644 --- a/r/R/dplyr-funcs-datetime.R +++ b/r/R/dplyr-funcs-datetime.R @@ -376,7 +376,7 @@ register_bindings_duration_helpers <- function() { function(x = 1) make_duration(x * value, unit) } - for (name in names(.helpers_function_map)){ + for (name in names(.helpers_function_map)) { register_binding( name, duration_helpers_map_factory( From cfae99ca03631c82ab751f685c44a0bc01576c3e Mon Sep 17 00:00:00 2001 From: Alenka Frim Date: Fri, 22 Apr 2022 06:26:48 +0200 Subject: [PATCH 23/23] Add info about the use of ignore_attr = TRUE in the tests --- r/tests/testthat/test-dplyr-funcs-datetime.R | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/r/tests/testthat/test-dplyr-funcs-datetime.R b/r/tests/testthat/test-dplyr-funcs-datetime.R index 7a51ddf9b5f..a4c5ee3c224 100644 --- a/r/tests/testthat/test-dplyr-funcs-datetime.R +++ b/r/tests/testthat/test-dplyr-funcs-datetime.R @@ -1260,6 +1260,11 @@ test_that("dminutes, dhours, ddays, dweeks, dmonths, dyears", { example_d <- tibble(x = c(1:10, NA)) date_to_add <- ymd("2009-08-03", tz = "Pacific/Marquesas") + # When comparing results we use ignore_attr = TRUE because of the diff in: + # attribute 'package' (absent vs. 'lubridate') + # class (difftime vs Duration) + # attribute 'units' (character vector ('secs') vs. absent) + compare_dplyr_binding( .input %>% mutate( @@ -1318,6 +1323,11 @@ test_that("dseconds, dmilliseconds, dmicroseconds, dnanoseconds, dpicoseconds", example_d <- tibble(x = c(1:10, NA)) date_to_add <- ymd("2009-08-03", tz = "Pacific/Marquesas") + # When comparing results we use ignore_attr = TRUE because of the diff in: + # attribute 'package' (absent vs. 'lubridate') + # class (difftime vs Duration) + # attribute 'units' (character vector ('secs') vs. absent) + compare_dplyr_binding( .input %>% mutate(