colearendt / tidyjson

Tidy your JSON data in R with tidyjson
Other
182 stars 14 forks source link

Quo path #132

Closed colearendt closed 3 years ago

colearendt commented 3 years ago

Close #129 Close #130

Both should now be possible - please give this a try and let me know if it works for you. Specifically to use within a function:

library(tidyjson)
#> 
#> Attaching package: 'tidyjson'
#> The following object is masked from 'package:stats':
#> 
#>     filter

enter_fix <- function(tbl_json, object) {
  tbl_json %>%
    enter_object(!!!object) %>%
    gather_array %>%
    spread_all %>%
    as_tibble()
}
enter_fix(worldbank, 'majorsector_percent')
#> # A tibble: 1,405 x 4
#>    document.id array.index Name                                    Percent
#>          <int>       <int> <chr>                                     <dbl>
#>  1           1           1 Education                                    46
#>  2           1           2 Education                                    26
#>  3           1           3 Public Administration, Law, and Justice      16
#>  4           1           4 Education                                    12
#>  5           2           1 Public Administration, Law, and Justice      70
#>  6           2           2 Public Administration, Law, and Justice      30
#>  7           3           1 Transportation                              100
#>  8           4           1 Health and other social services            100
#>  9           5           1 Industry and trade                           50
#> 10           5           2 Industry and trade                           40
#> # … with 1,395 more rows

Created on 2021-01-02 by the reprex package (v0.3.0)