paleolimbot commented on issue #14476:
URL: https://github.com/apache/arrow/issues/14476#issuecomment-1292812367

   We really should have an easy `StructArray$create()`. We have a binding for 
this in dplyr, which allows a workaround until we add this properly!
   
   ``` r
   library(arrow, warn.conflicts = FALSE)
   
   make_struct <- function(...) {
     args <- rlang::enquos(..., .named = TRUE)
     syms <- rlang::set_names(rlang::syms(names(args)), names(args))
     table <- arrow_table(tibble::tibble(!!! args)) |> 
       dplyr::transmute(tibble::tibble(!!! syms)) |> 
       dplyr::compute()
     as_arrow_array(table[[1]])
   }
   
   make_struct(a = 1:5, b = letters[1:5])
   #> StructArray
   #> <struct<a: int32, b: string>>
   #> -- is_valid: all not null
   #> -- child 0 type: int32
   #>   [
   #>     1,
   #>     2,
   #>     3,
   #>     4,
   #>     5
   #>   ]
   #> -- child 1 type: string
   #>   [
   #>     "a",
   #>     "b",
   #>     "c",
   #>     "d",
   #>     "e"
   #>   ]
   ```
   
   <sup>Created on 2022-10-26 with [reprex 
v2.0.2](https://reprex.tidyverse.org)</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