You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@arrow.apache.org by "SHIMA Tatsuya (Jira)" <ji...@apache.org> on 2022/07/20 10:29:00 UTC

[jira] [Created] (ARROW-17143) [R] Add examples working with `tidyr::unnest`and `tidyr::unnest_longer`

SHIMA Tatsuya created ARROW-17143:
-------------------------------------

             Summary: [R] Add examples working with `tidyr::unnest`and `tidyr::unnest_longer`
                 Key: ARROW-17143
                 URL: https://issues.apache.org/jira/browse/ARROW-17143
             Project: Apache Arrow
          Issue Type: Improvement
          Components: Documentation, R
    Affects Versions: 8.0.1
            Reporter: SHIMA Tatsuya


Related to ARROW-8813

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.

{code:r}
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
{code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)