Dewey Dunnington created ARROW-16266:
----------------------------------------

             Summary: [R] Add StructArray$create()
                 Key: ARROW-16266
                 URL: https://issues.apache.org/jira/browse/ARROW-16266
             Project: Apache Arrow
          Issue Type: Improvement
          Components: R
            Reporter: Dewey Dunnington


In ARROW-13371 we implemented the {{make_struct}} compute function bound to 
{{data.frame()}} / {{tibble()}} in dplyr evaluation; however, we didn't 
actually implement {{StructArray$create()}}. In ARROW-15168, it turns out that 
we need to do this to support {{StructArray}} creation from data.frames whose 
columns aren't all convertable using the internal C++ conversion. The hack used 
in that PR is below (but we should clearly implement the C++ function instead 
of using the hack):

{code:R}
library(arrow, warn.conflicts = FALSE)

struct_array <- function(...) {
  batch <- record_batch(...)
  array_ptr <- arrow:::allocate_arrow_array()
  schema_ptr <- arrow:::allocate_arrow_schema()
  batch$export_to_c(array_ptr, schema_ptr)
  Array$import_from_c(array_ptr, schema_ptr)
}

struct_array(a = 1, b = "two")
#> StructArray
#> <struct<a: double, b: string>>
#> -- is_valid: all not null
#> -- child 0 type: double
#>   [
#>     1
#>   ]
#> -- child 1 type: string
#>   [
#>     "two"
#>   ]
{code}




--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to