We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
introduction-to-tidyjson.Rmd
parse error: premature EOF
> knitr::opts_chunk$set(collapse = T, comment = "#>") > options(tibble.print_min = 4, tibble.print_max = 4) > library(tidyjson) Attaching package: ‘tidyjson’ The following object is masked from ‘package:stats’: filter > library(dplyr) Attaching package: ‘dplyr’ The following objects are masked from ‘package:stats’: filter, lag The following objects are masked from ‘package:base’: intersect, setdiff, setequal, union > people <- c("{\"age\": 32, \"name\": {\"first\": \"Bob\", \"last\": \"Smith\"}}", + "{\"age\": 54, \"name\": {\"first\": \"Susan\", \"last\": ..." ... [TRUNCATED] > people %>% spread_all # A tbl_json: 3 x 5 tibble with a "JSON" attribute ..JSON document.id age name.first name.last <chr> <int> <dbl> <chr> <chr> 1 "{\"age\":32,\"name..." 1 32 Bob Smith 2 "{\"age\":54,\"name..." 2 54 Susan Doe 3 "{\"age\":18,\"name..." 3 18 Ann Jones > worldbank %>% str chr [1:500] "{\"_id\":{\"$oid\":\"52b213b38594d8a2be17c780\"},\"boardapprovaldate\":\"2013-11-12T00:00:00Z\",\"closingdate\""| __truncated__ ... > worldbank %>% spread_all # A tbl_json: 500 x 9 tibble with a "JSON" attribute ..JSON document.id boardapprovaldate closingdate countryshortname project_name <chr> <int> <chr> <chr> <chr> <chr> 1 "{\"_… 1 2013-11-12T00:00… 2018-07-07… Ethiopia Ethiopia Ge… 2 "{\"_… 2 2013-11-04T00:00… <NA> Tunisia TN: DTF Soc… 3 "{\"_… 3 2013-11-01T00:00… <NA> Tuvalu Tuvalu Avia… 4 "{\"_… 4 2013-10-31T00:00… <NA> Yemen, Republic… Gov't and C… # ℹ 496 more rows # ℹ 3 more variables: regionname <chr>, totalamt <dbl>, `_id.$oid` <chr> > worldbank %>% spread_all %>% select(regionname, totalamt) # A tbl_json: 500 x 3 tibble with a "JSON" attribute ..JSON regionname totalamt <chr> <chr> <dbl> 1 "{\"_id\":{\"$oid\":..." Africa 130000000 2 "{\"_id\":{\"$oid\":..." Middle East and North Africa 0 3 "{\"_id\":{\"$oid\":..." East Asia and Pacific 6060000 4 "{\"_id\":{\"$oid\":..." Middle East and North Africa 0 # ℹ 496 more rows > options(tibble.print_min = 10, tibble.print_max = 10) > worldbank %>% gather_object %>% json_types %>% count(name, + type) # A tibble: 8 × 3 name type n <chr> <fct> <int> 1 _id object 500 2 boardapprovaldate string 500 3 closingdate string 370 4 countryshortname string 500 5 majorsector_percent array 500 6 project_name string 500 7 regionname string 500 8 totalamt number 500 > options(tibble.print_min = 4, tibble.print_max = 4) > worldbank %>% enter_object(majorsector_percent) # A tbl_json: 500 x 2 tibble with a "JSON" attribute ..JSON document.id <chr> <int> 1 "[{\"Name\":\"Educa..." 1 2 "[{\"Name\":\"Publi..." 2 3 "[{\"Name\":\"Trans..." 3 4 "[{\"Name\":\"Healt..." 4 # ℹ 496 more rows > worldbank %>% enter_object(majorsector_percent) %>% + gather_array # A tbl_json: 1,405 x 3 tibble with a "JSON" attribute ..JSON document.id array.index <chr> <int> <int> 1 "{\"Name\":\"Educat..." 1 1 2 "{\"Name\":\"Educat..." 1 2 3 "{\"Name\":\"Public..." 1 3 4 "{\"Name\":\"Educat..." 1 4 # ℹ 1,401 more rows > worldbank %>% enter_object(majorsector_percent) %>% + gather_array %>% spread_all # A tbl_json: 1,405 x 5 tibble with a "JSON" attribute ..JSON document.id array.index Name Percent <chr> <int> <int> <chr> <dbl> 1 "{\"Name\":\"Educat..." 1 1 Education 46 2 "{\"Name\":\"Educat..." 1 2 Education 26 3 "{\"Name\":\"Public..." 1 3 Public Administration… 16 4 "{\"Name\":\"Educat..." 1 4 Education 12 # ℹ 1,401 more rows > worldbank %>% spread_all %>% select(region = regionname, + funding = totalamt) %>% enter_object(majorsector_percent) %>% + gather_array %> .... [TRUNCATED] `summarise()` has grouped output by 'region'. You can override using the `.groups` argument. # A tibble: 63 × 3 # Groups: region [7] region sector funding <chr> <chr> <dbl> 1 Africa Agriculture, fishing, and forestry 96648500000 2 Africa Education 83370000000 3 Africa Energy and mining 86709960000 4 Africa Finance 30761000000 # ℹ 59 more rows > worldbank %>% spread_all %>% select(regionname, totalamt) # A tbl_json: 500 x 3 tibble with a "JSON" attribute ..JSON regionname totalamt <chr> <chr> <dbl> 1 "{\"_id\":{\"$oid\":..." Africa 130000000 2 "{\"_id\":{\"$oid\":..." Middle East and North Africa 0 3 "{\"_id\":{\"$oid\":..." East Asia and Pacific 6060000 4 "{\"_id\":{\"$oid\":..." Middle East and North Africa 0 # ℹ 496 more rows > worldbank %>% gather_object %>% json_types %>% count(name, + type) # A tibble: 8 × 3 name type n <chr> <fct> <int> 1 _id object 500 2 boardapprovaldate string 500 3 closingdate string 370 4 countryshortname string 500 # ℹ 4 more rows > worldbank %>% enter_object(majorsector_percent) %>% + gather_array # A tbl_json: 1,405 x 3 tibble with a "JSON" attribute ..JSON document.id array.index <chr> <int> <int> 1 "{\"Name\":\"Educat..." 1 1 2 "{\"Name\":\"Educat..." 1 2 3 "{\"Name\":\"Public..." 1 3 4 "{\"Name\":\"Educat..." 1 4 # ℹ 1,401 more rows > companies[1] %>% gather_object %>% filter(is_json_array(.)) %>% + gather_array # A tbl_json: 8 x 4 tibble with a "JSON" attribute ..JSON document.id name array.index <chr> <int> <chr> <int> 1 "{\"is_past\":fals..." 1 relationships 1 2 "{\"id\":6252,\"rou..." 1 funding_rounds 1 3 "{\"id\":15229,\"ro..." 1 funding_rounds 2 4 "{\"id\":22565,\"ro..." 1 funding_rounds 3 # ℹ 4 more rows > companies[1] %>% gather_object %>% filter(is_json_object(.)) %>% + gather_object Warning in gather_object(.) : name column name already exists, changing to name.2 # A tbl_json: 3 x 4 tibble with a "JSON" attribute ..JSON document.id name name.2 <chr> <int> <chr> <chr> 1 "\"52cdef7e4bab8b..." 1 _id $oid 2 "[[[150,22],\"ass..." 1 image available_sizes 3 "null" 1 image attribution > json <- "{\"2015\": 5, \"2016\": 10}" > json %>% gather_object("year") %>% append_values_number("count") # A tbl_json: 2 x 4 tibble with a "JSON" attribute ..JSON document.id year count <chr> <int> <chr> <dbl> 1 5 1 2015 5 2 10 1 2016 10 > worldbank %>% as.tbl_json # A tbl_json: 500 x 2 tibble with a "JSON" attribute ..JSON document.id <chr> <int> 1 "{\"_id\":{\"$oid\":..." 1 2 "{\"_id\":{\"$oid\":..." 2 3 "{\"_id\":{\"$oid\":..." 3 4 "{\"_id\":{\"$oid\":..." 4 # ℹ 496 more rows > bad_json <- "{\"key\": \"value\"" > bad_json %>% as.tbl_json When sourcing ‘introduction-to-tidyjson.R’: Error: ℹ In index: 1. Caused by error: ! parse error: premature EOF {"key": "value" (right here) ------^ Execution halted
All tests pass.
The text was updated successfully, but these errors were encountered:
No branches or pull requests
All tests pass.
The text was updated successfully, but these errors were encountered: