Title: | Examples of Recursive Lists and Nested or Split Data Frames |
---|---|
Description: | Recursive lists in the form of R objects, 'JSON', and 'XML', for use in teaching and examples. Examples include color palettes, Game of Thrones characters, 'GitHub' users and repositories, music collections, and entities from the Star Wars universe. Data from the 'gapminder' package is also included, as a simple data frame and in nested and split forms. |
Authors: | Jennifer Bryan [aut, cre] , Charlotte Wickham [ctb], Posit Software, PBC [cph, fnd] |
Maintainer: | Jennifer Bryan <[email protected]> |
License: | CC0 |
Version: | 1.1.0.9000 |
Built: | 2024-11-29 02:51:51 UTC |
Source: | https://github.com/jennybc/repurrrsive |
A music collection, as represented in a recursive list returned from the Discogs API.
discog
discog
A unnamed list with 155 components, each representing an item in Sharla's music collection.
Data retrieved on 2019-07-15 from https://www.discogs.com
Original blog post by Sharla Gelfand https://sharla.party/post/discog-purrr/
Other Discogs data and functions:
discog_json()
length(discog) str(discog, max.level = 2, list.len = 2) vapply(discog[1:6], `[[`, c("basic_information", "title"), FUN.VALUE = "")
length(discog) str(discog, max.level = 2, list.len = 2) vapply(discog[1:6], `[[`, c("basic_information", "title"), FUN.VALUE = "")
Path to Discogs data as JSON
discog_json()
discog_json()
Local path to JSON file containing Discogs data
Other Discogs data and functions:
discog
discog_json() if (require("jsonlite")) { d <- fromJSON(discog_json(), simplifyVector = FALSE) identical(discog, d) }
discog_json() if (require("jsonlite")) { d <- fromJSON(discog_json(), simplifyVector = FALSE) identical(discog, d) }
The main data frame from the gapminder
package in three forms:
gap_simple
, same as gapminder::gapminder
gap_nested
, nested by country and continent
gap_split
, split by country
gap_simple gap_nested gap_split
gap_simple gap_nested gap_split
An object of class tbl_df
(inherits from tbl
, data.frame
) with 1704 rows and 6 columns.
gap_simple gap_nested str(gap_split, max.level = 1, list.len = 10) str(gap_split[[1]])
gap_simple gap_nested str(gap_split, max.level = 1, list.len = 10) str(gap_split[[1]])
Info on GitHub repos, retrieved from the GitHub API.
gh_repos
gh_repos
A unnamed list with 6 components, each itself a list of 30 repos for a specific GitHub user. Each repo's component is a list of length >60, containing information such as name, owner (a list), fork status, and creation date.
https://developer.github.com/v3/repos/#list-user-repositories
Other GitHub data and functions:
gh_users_json()
,
gh_users
str(gh_repos, max.level = 1) str(gh_repos[[1]], max.level = 1) str(gh_repos[[1]][[1]]) str(lapply(gh_repos[[1]][1:3], `[`, c("full_name", "created_at")))
str(gh_repos, max.level = 1) str(gh_repos[[1]], max.level = 1) str(gh_repos[[1]][[1]]) str(lapply(gh_repos[[1]][1:3], `[`, c("full_name", "created_at")))
Info on GitHub users, retrieved from the GitHub API.
gh_users
gh_users
A unnamed list with 6 components, each representing a GitHub user. Each user's component is a list of length 30, containing information such as username, GitHub id, and join date.
https://developer.github.com/v3/users/#get-a-single-user
Other GitHub data and functions:
gh_repos
,
gh_users_json()
str(gh_users, max.level = 1) str(gh_users[[1]]) str(lapply(gh_users, `[`, c("login", "name")))
str(gh_users, max.level = 1) str(gh_users[[1]]) str(lapply(gh_users, `[`, c("login", "name")))
Paths to GitHub data as JSON and XML
gh_users_json() gh_repos_json() gh_users_xml() gh_repos_xml()
gh_users_json() gh_repos_json() gh_users_xml() gh_repos_xml()
Local path to JSON or XML file containing GitHub data
Other GitHub data and functions:
gh_repos
,
gh_users
gh_users_json() if (require("jsonlite")) { ghuj <- fromJSON(gh_users_json(), simplifyDataFrame = FALSE) identical(gh_users, ghuj) } gh_repos_json() if (require("jsonlite")) { ghrj <- fromJSON(gh_repos_json(), simplifyDataFrame = FALSE) identical(gh_repos, ghrj) } gh_users_xml() if (require("xml2")) { xml <- read_xml(gh_users_xml()) xml } gh_repos_xml() if (require("xml2")) { xml <- read_xml(gh_repos_xml()) xml }
gh_users_json() if (require("jsonlite")) { ghuj <- fromJSON(gh_users_json(), simplifyDataFrame = FALSE) identical(gh_users, ghuj) } gh_repos_json() if (require("jsonlite")) { ghrj <- fromJSON(gh_repos_json(), simplifyDataFrame = FALSE) identical(gh_repos, ghrj) } gh_users_xml() if (require("xml2")) { xml <- read_xml(gh_users_xml()) xml } gh_repos_xml() if (require("xml2")) { xml <- read_xml(gh_repos_xml()) xml }
This tibble contains the results of geocoding five cities ("Houston", "Washington", "New York", "Chicago", "Arlington") using the Google Maps API on 2022-06-08. Two cities, Washington and Arlington, were deliberately picked for their ambiguity: Washington could refer to the city or the state, and Arlington could mean the one in Virginia or the one in Texas.
gmaps_cities
gmaps_cities
A tibble with 5 rows and two columns. city
gives the original
search term and json
gives the returned JSON converted to a list.
https://developers.google.com/maps/documentation/geocoding
gmaps_cities
gmaps_cities
Info on the point-of-view (POV) characters from the first five books in the Song of Ice and Fire series by George R. R. Martin. Retrieved from An API Of Ice And Fire.
got_chars
got_chars
A unnamed list with 30 components, each representing a POV character. Each character's component is a named list of length 18, containing information such as name, aliases, and house allegiances.
Other Game of Thrones data and functions:
got_chars_json()
str(got_chars, max.level = 1, list.len = 10) str(got_chars[[1]]) str(lapply(got_chars, `[`, c("name", "culture")))
str(got_chars, max.level = 1, list.len = 10) str(got_chars[[1]]) str(lapply(got_chars, `[`, c("name", "culture")))
Paths to Game of Thrones data as JSON and XML
got_chars_json() got_chars_xml()
got_chars_json() got_chars_xml()
Local path to JSON or XML file containing Game of Thrones data
Other Game of Thrones data and functions:
got_chars
got_chars_json() if (require("jsonlite")) { gotcj <- fromJSON(got_chars_json(), simplifyDataFrame = FALSE) identical(got_chars, gotcj) } got_chars_xml() if (require("xml2")) { xml <- read_xml(got_chars_xml()) xml }
got_chars_json() if (require("jsonlite")) { gotcj <- fromJSON(got_chars_json(), simplifyDataFrame = FALSE) identical(got_chars, gotcj) } got_chars_xml() if (require("xml2")) { xml <- read_xml(got_chars_xml()) xml }
Data retrieved from the swapi API on the Star Wars Universe.
sw_people sw_films sw_planets sw_species sw_vehicles sw_starships
sw_people sw_films sw_planets sw_species sw_vehicles sw_starships
Unnamed lists with varying number of components.
sw_people
List of individual people or characters within the Star Wars universe.
sw_starships
List of transport crafts with hyperdrive capability.
sw_vehicles
List of transport crafts without hyperdrive capability.
sw_films
List of Star Wars films.
sw_species
List of types of people or characters within the Star Wars Universe.
sw_planets
List of large masses, planets or planetoids in the Star Wars Universe, at the time of 0 ABY.
Data originally obtained from http://swapi.co/
using the rwars
package: https://github.com/Ironholds/rwars. The Star Wars API appears to
have moved to https://pipedream.com/apps/swapi
since that time.
# sw_people str(sw_people, max.level = 1) str(sw_people[[1]]) sapply(sw_people, `[[`, "name") # sw_films str(sw_films, max.level = 1) str(sw_films[[1]]) sapply(sw_films, `[[`, "title")
# sw_people str(sw_people, max.level = 1) str(sw_people[[1]]) sapply(sw_people, `[[`, "name") # sw_films str(sw_films, max.level = 1) str(sw_films[[1]]) sapply(sw_films, `[[`, "title")
A list of color palettes inspired by Wes Anderson movies, taken from the from wesanderson package.
wesanderson
wesanderson
A named list with 15 components, each containing a color palette from a specific movie. Each palette consists of 4 or 5 hexadecimal color values.
https://cran.r-project.org/package=wesanderson
http://wesandersonpalettes.tumblr.com
Other wesanderson data and functions:
wesanderson_json()
str(wesanderson)
str(wesanderson)
Path to wesanderson JSON and XML
wesanderson_json() wesanderson_xml()
wesanderson_json() wesanderson_xml()
Local path to JSON or XML file containing Wes Anderson color palettes
Other wesanderson data and functions:
wesanderson
wesanderson_json() if (require("jsonlite")) { jsonlite::fromJSON(wesanderson_json()) } wesanderson_xml() if (require("xml2")) { xml2::read_xml(wesanderson_xml()) }
wesanderson_json() if (require("jsonlite")) { jsonlite::fromJSON(wesanderson_json()) } wesanderson_xml() if (require("xml2")) { xml2::read_xml(wesanderson_xml()) }