You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/04/13 12:19:29 UTC

[GitHub] [arrow] dragosmg commented on a diff in pull request #12855: ARROW-14942: [R] Bindings for lubridate's dpicoseconds, dnanoseconds, desconds, dmilliseconds, dmicroseconds

dragosmg commented on code in PR #12855:
URL: https://github.com/apache/arrow/pull/12855#discussion_r849416453


##########
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()))

Review Comment:
   You could replace `Expression$create()` with `build_expr()` which then allows you to get rid of the `if (!inherits(x, "Expression"))` logic.
   `build_expr()` is in fact `Expression$create()` plus an automatic conversion of R objects to Scalar. 



##########
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()))

Review Comment:
   You could replace `Expression$create()` with `build_expr()` which then allows you to get rid of the `if (!inherits(x, "Expression"))` logic.
   `build_expr()` is in fact `Expression$create()` plus an automatic conversion of R objects to Scalar. 



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org