diff --git a/R/data-worldbank.r b/R/data-worldbank.r index 6264b33..97549f3 100644 --- a/R/data-worldbank.r +++ b/R/data-worldbank.r @@ -20,7 +20,7 @@ #' name = jstring("project_name"), # Spread name #' region = jstring("regionname") # Spread region #' ) %>% -#' enter_object("sector") %>% # Enter the 'sector' object +#' enter_object("majorsector_percent") %>% # Enter the 'sector' object #' gather_array("sector.index") %>% # Gather the array #' spread_values(sector = jstring("Name")) # Spread the sector name #' diff --git a/data/worldbank.rda b/data/worldbank.rda index 2610b63..39accc8 100644 Binary files a/data/worldbank.rda and b/data/worldbank.rda differ diff --git a/man/worldbank.Rd b/man/worldbank.Rd index e150969..b8ccf72 100644 --- a/man/worldbank.Rd +++ b/man/worldbank.Rd @@ -24,7 +24,7 @@ wb_sectors <- worldbank \%>\% # 500 Projects funded by the world bank name = jstring("project_name"), # Spread name region = jstring("regionname") # Spread region ) \%>\% - enter_object("sector") \%>\% # Enter the 'sector' object + enter_object("majorsector_percent") \%>\% # Enter the 'sector' object gather_array("sector.index") \%>\% # Gather the array spread_values(sector = jstring("Name")) # Spread the sector name diff --git a/vignettes/introduction-to-tidyjson.Rmd b/vignettes/introduction-to-tidyjson.Rmd index e164a11..0333129 100644 --- a/vignettes/introduction-to-tidyjson.Rmd +++ b/vignettes/introduction-to-tidyjson.Rmd @@ -9,6 +9,10 @@ vignette: > %\usepackage[utf8]{inputenc} --- +```{r, echo = FALSE} +knitr::opts_chunk$set(collapse = TRUE, comment = "#>") +``` + [JSON](http://json.org/) (JavaScript Object Notation) is a lightweight and flexible data format that is easy for humans to read and for machines to parse. JSON has become a common format used in: @@ -386,21 +390,15 @@ a specific key. ## A real example Included in the tidyjson package is a `r length(worldbank)` record sample, -`worldbank`, which contains world bank funded projects from -[jsonstudio](http://jsonstudio.com/resources/). +`worldbank`, which contains a subset of the JSON data describing world bank +funded projects from [jsonstudio](http://jsonstudio.com/resources/). First, let's take a look at a single record. We can use `jsonlite::prettify` to -make the JSON easy to read. But because some of the text is very -lengthy (e.g., the abstract and many URLs), we are going to jump through some -hoops to truncate the result to 80 characters so it will fit in the vignette: +make the JSON easy to read: ```{r} library(jsonlite) -library(stringr) -worldbank[1] %>% prettify %>% - str_split("\n") %>% unlist %>% - lapply(str_sub, 1, 80) %>% paste(collapse = "\n") %>% - writeLines +worldbank[1] %>% prettify ``` An interesting objects is "majorsector_percent", which appears to capture the