dragosmg commented on a change in pull request #12319:
URL: https://github.com/apache/arrow/pull/12319#discussion_r820096911
##########
File path: r/R/dplyr-funcs-type.R
##########
@@ -292,3 +293,18 @@ register_bindings_type_elementwise <- function() {
is_inf & !call_binding("is.na", is_inf)
})
}
+
+register_bindings_type_format <- function() {
+ register_binding("format", function(x, ...) {
+ if (!inherits(x, "Expression")) {
+ return(format(x, ...))
+ }
+
+ if (inherits(x, "Expression") &&
+ x$type_id() %in% Type[c("TIMESTAMP", "DATE32", "DATE64")]) {
+ binding_format_datetime(x, ...)
+ } else {
+ x$cast(string())
Review comment:
I think relying on format if `x` isn't an `Expression` is really helpful
with R objects. The example below fails when we get rid of the part that
returns early if `x` isn't an `Expression`.
```r
compare_dplyr_binding(
.input %>%
mutate(x = format(1),
y = format(13.7, nsmall = 3)) %>%
collect(),
times
)
```
because falling back on casting to string does not take into account the
`small = 3` argument:
```r
Error: `object` (`actual`) not equal to `expected` (`expected`).
actual vs expected
y
- actual[1, ] 13.7
+ expected[1, ] 13.700
- actual[2, ] 13.7
+ expected[2, ] 13.700
`actual$y`: "13.7" "13.7"
`expected$y`: "13.700" "13.700"
```
--
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]