dragosmg commented on code in PR #12757:
URL: https://github.com/apache/arrow/pull/12757#discussion_r853868151
##########
r/R/dplyr-funcs-datetime.R:
##########
@@ -372,3 +391,36 @@ binding_format_datetime <- function(x, format = "", tz =
"", usetz = FALSE) {
build_expr("strftime", x, options = list(format = format, locale =
Sys.getlocale("LC_TIME")))
}
+
+# this is a helper function used for creating a difftime / duration objects
from
+# several of the accepted pieces (second, minute, hour, day, week)
+duration_from_chunks <- function(chunks) {
+ accepted_chunks <- c("second", "minute", "hour", "day", "week")
+ matched_chunks <- accepted_chunks[pmatch(names(chunks), accepted_chunks,
duplicates.ok = TRUE)]
+
+ if (any(is.na(matched_chunks))) {
+ abort(
+ paste0(
+ "named `difftime` units other than: ",
+ oxford_paste(accepted_chunks, quote_symbol = "`"),
+ " not supported in Arrow. \nInvalid `difftime` parts: ",
+ oxford_paste(names(chunks[is.na(matched_chunks)]), quote_symbol = "`")
+ )
+ )
+ }
+
+ matched_chunks <- matched_chunks[!is.na(matched_chunks)]
+
+ chunks <- chunks[matched_chunks]
+ chunk_duration <- c(
+ "second" = 1L,
+ "minute" = 60L,
+ "hour" = 3600L,
+ "day" = 86400L,
+ "week" = 604800L
+ )
+ # transform the duration of each chunk in seconds and add everything together
+ chunks_total <- purrr::imap(chunks, ~.x * chunk_duration[[.y]]) %>%
+ purrr::reduce(`+`)
+ chunks_total
Review Comment:
Done. No longer using the magrittr pipe.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]