dragosmg commented on a change in pull request #12433:
URL: https://github.com/apache/arrow/pull/12433#discussion_r812745417



##########
File path: r/R/dplyr-funcs-datetime.R
##########
@@ -147,5 +147,7 @@ register_bindings_datetime <- function() {
   register_binding("pm", function(x) {
     !call_binding("am", x)
   })
-
+  register_binding("date", function(x) {
+    x$cast(date32())
+  })

Review comment:
       Recycling a vector of length one works. 
   ``` r
   suppressPackageStartupMessages(library(arrow))
   suppressPackageStartupMessages(library(dplyr))
   suppressPackageStartupMessages(library(lubridate))
   
   arbitrary_date_object <- ymd_hms("2012-03-26 23:12:13")
   # dplyr pipeline
   mtcars %>% 
     mutate(x = arbitrary_date_object) %>% 
     head(4)
   #>                 mpg cyl disp  hp drat    wt  qsec vs am gear carb
   #> Mazda RX4      21.0   6  160 110 3.90 2.620 16.46  0  1    4    4
   #> Mazda RX4 Wag  21.0   6  160 110 3.90 2.875 17.02  0  1    4    4
   #> Datsun 710     22.8   4  108  93 3.85 2.320 18.61  1  1    4    1
   #> Hornet 4 Drive 21.4   6  258 110 3.08 3.215 19.44  1  0    3    1
   #>                                  x
   #> Mazda RX4      2012-03-26 23:12:13
   #> Mazda RX4 Wag  2012-03-26 23:12:13
   #> Datsun 710     2012-03-26 23:12:13
   #> Hornet 4 Drive 2012-03-26 23:12:13
   
   # arrow pipeline
   mtcars %>% 
     arrow_table() %>% 
     mutate(x = arbitrary_date_object) %>% 
     collect() %>% 
     head(4)
   #>    mpg cyl disp  hp drat    wt  qsec vs am gear carb                   x
   #> 1 21.0   6  160 110 3.90 2.620 16.46  0  1    4    4 2012-03-26 23:12:13
   #> 2 21.0   6  160 110 3.90 2.875 17.02  0  1    4    4 2012-03-26 23:12:13
   #> 3 22.8   4  108  93 3.85 2.320 18.61  1  1    4    1 2012-03-26 23:12:13
   #> 4 21.4   6  258 110 3.08 3.215 19.44  1  0    3    1 2012-03-26 23:12:13
   ```
   
   <sup>Created on 2022-02-23 by the [reprex 
package](https://reprex.tidyverse.org) (v2.0.1)</sup>




-- 
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]


Reply via email to