Skip to content

[R] Add examples working with tidyr::unnestand tidyr::unnest_longer #20329

@asfimport

Description

@asfimport

Related to ARROW-8813 ARROW-12099

The arrow package can convert json files to data frames very easily, but tidyr::unnest_longer is needed for array expansion.
Wonder if tidyr could be added to the recommended package and examples like this could be included in the documentation and test cases.

tf <- tempfile()
on.exit(unlink(tf))
writeLines('
    { "hello": 3.5, "world": false, "foo": { "bar": [ 1, 2 ] } }
    { "hello": 3.25, "world": null }
    { "hello": 0.0, "world": true, "foo": { "bar": [ 3, 4, 5 ] } }
  ', tf)

arrow::read_json_arrow(tf) |>
  tidyr::unnest(foo, names_sep = ".") |>
  tidyr::unnest_longer(foo.bar)
#> # A tibble: 6 × 3
#>   hello world foo.bar
#>   <dbl> <lgl>   <int>
#> 1  3.5  FALSE       1
#> 2  3.5  FALSE       2
#> 3  3.25 NA         NA
#> 4  0    TRUE        3
#> 5  0    TRUE        4
#> 6  0    TRUE        5

Reporter: SHIMA Tatsuya / @eitsupi

Note: This issue was originally created as ARROW-17143. Please see the migration documentation for further details.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions