You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@arrow.apache.org by "Neal Richardson (Jira)" <ji...@apache.org> on 2022/07/20 13:20:00 UTC
[jira] [Commented] (ARROW-17143) [R] Add examples working with `tidyr::unnest`and `tidyr::unnest_longer`
[ https://issues.apache.org/jira/browse/ARROW-17143?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17569015#comment-17569015 ]
Neal Richardson commented on ARROW-17143:
-----------------------------------------
These tidyr functions aren't working on Arrow Tables, they're working on the R data.frame that read_json_arrow returns. I guess you could add something about this to the cookbook, but there's no real connection to anything in the package itself.
> [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
> Priority: Major
>
> 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.
> {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)