romainfrancois commented on pull request #11805:
URL: https://github.com/apache/arrow/pull/11805#issuecomment-985367918
Perhaps we could have something like this on the R side:
```r
Array$create <- function(x, type = NULL) {
if (!is.null(type)) {
type <- as_type(type)
}
if (inherits(x, "Scalar")) {
out <- x$as_array()
if (!is.null(type)) {
out <- out$cast(type)
}
return(out)
}
tryCatch(
vec_to_Array(x, type),
error = function(cnd) {
if (!is.null(type)) {
# try again and then cast
vec_to_Array(x, NULL)$cast(type)
} else {
signalCondition(cnd)
}
}
)
}
```
So that:
``` r
library(arrow, warn.conflicts = FALSE)
#> See arrow_info() for available features
Array$create(c(1, 2), type = decimal(4, 3))
#> Array
#> <decimal128(4, 3)>
#> [
#> 1.000,
#> 2.000
#> ]
```
<sup>Created on 2021-12-03 by the [reprex
package](https://reprex.tidyverse.org) (v2.0.1.9000)</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]