Uploaded image for project: 'Apache Arrow'
  1. Apache Arrow
  2. ARROW-17143

[R] Add examples working with `tidyr::unnest`and `tidyr::unnest_longer`

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 8.0.1
    • None
    • Documentation, R
    • None

    Description

      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
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            eitsupi SHIMA Tatsuya
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: