Skip to content

Commit

Permalink
#29 simplify worldbank example to a smaller subset of data
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Stanley committed Apr 11, 2015
1 parent 5c82fa8 commit 198bf3d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion R/data-worldbank.r
Original file line number Diff line number Diff line change
Expand Up @@ -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
#'
Expand Down
Binary file modified data/worldbank.rda
Binary file not shown.
2 changes: 1 addition & 1 deletion man/worldbank.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 8 additions & 10 deletions vignettes/introduction-to-tidyjson.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 198bf3d

Please sign in to comment.