dragosmg commented on a change in pull request #12506:
URL: https://github.com/apache/arrow/pull/12506#discussion_r823607966
##########
File path: r/R/dplyr-funcs-type.R
##########
@@ -120,6 +120,42 @@ register_bindings_type_cast <- function() {
}
build_expr("cast", x, options = cast_options(to_type = date32()))
})
+ register_binding("as.difftime", function(x,
+ format = "%X",
+ units = "auto",
+ tz = "UTC") {
+ # windows doesn't seem to like "%X"
+ if (format == "%X" & tolower(Sys.info()[["sysname"]]) == "windows") {
+ format <- "%H:%M:%S"
+ }
+
+ if (units != "secs") {
+ abort("`as.difftime()` with units other than seconds not supported in
Arrow")
+ }
+
+ if (call_binding("is.character", x)) {
+ x <- build_expr("strptime", x, options = list(format = format, tz = tz,
unit = 0L))
+ y <- build_expr("strptime", "0:0:0", options = list(format = "%H:%M:%S",
tz = tz, unit = 0L))
+ diff_x_y <- call_binding("difftime", x, y, units = "secs", tz = tz)
+ return(diff_x_y)
+ }
+
+ # numeric -> duration not supported in Arrow yet so we use time23() as
+ # intermediate step
+ # TODO revisit once https://issues.apache.org/jira/browse/ARROW-15862 done
+ if (call_binding("is.numeric", x)) {
Review comment:
Done. Thanks for the suggestion. It makes a lot of sense.
--
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]