Learn R Programming

repurrrsive

The repurrrsive package provides recursive lists that are handy when teaching or exampling functions such as purrr::map() and the rectangling functions in the tidyr package. The datasets are stored as R list, JSON, and XML to provide the full non-rectangular data experience. Enjoy!

This package also includes the main data frame from the gapminder package in 3 different forms: simple data frame (no list-columns), data frame nested by country, and split into a named list of data frames.

Installation

You can install repurrrsive from CRAN like so:

install.packages("repurrrsive")

or from GitHub with:

# install.packages("devtools")
devtools::install_github("jennybc/repurrrsive")

Recursive list examples

repurrrsive contains several datasets that are recursive lists, both in the form of R objects and as JSON and/or XML files.

For example, got_chars is a list with information on the 30 point-of-view characters from the first five books in the Song of Ice and Fire series by George R. R. Martin. Here’s how to use purrr::map_chr() to extract the character’s names:

library(repurrrsive)
library(purrr)

map_chr(got_chars, "name")
#>  [1] "Theon Greyjoy"      "Tyrion Lannister"   "Victarion Greyjoy" 
#>  [4] "Will"               "Areo Hotah"         "Chett"             
#>  [7] "Cressen"            "Arianne Martell"    "Daenerys Targaryen"
#> [10] "Davos Seaworth"     "Arya Stark"         "Arys Oakheart"     
#> [13] "Asha Greyjoy"       "Barristan Selmy"    "Varamyr"           
#> [16] "Brandon Stark"      "Brienne of Tarth"   "Catelyn Stark"     
#> [19] "Cersei Lannister"   "Eddard Stark"       "Jaime Lannister"   
#> [22] "Jon Connington"     "Jon Snow"           "Aeron Greyjoy"     
#> [25] "Kevan Lannister"    "Melisandre"         "Merrett Frey"      
#> [28] "Quentyn Martell"    "Samwell Tarly"      "Sansa Stark"

Each set of recursive lists has its own article that gives a sense of what sort of manipulations can be demonstrated with the dataset(s):

  • Game of Thrones characters
  • Data on entities in the Star Wars universe
  • GitHub user and repo data
  • Sharla Gelfand’s music collection
  • Color palettes from Wes Anderson movies

Learn more at https://jennybc.github.io/repurrrsive/articles/.

Nested and split data frames

The Gapminder data, from the gapminder package, is also here in various forms to allow practice of different styles of grouped computation.

For example, the gap_nested dataset has one row per country, with a nested data column containing longitudinal data for life expectancy, population, and GDP per capita.

gap_nested
#> # A tibble: 142 × 3
#>    country     continent data             
#>    <fct>       <fct>     <list>           
#>  1 Afghanistan Asia      <tibble [12 × 4]>
#>  2 Albania     Europe    <tibble [12 × 4]>
#>  3 Algeria     Africa    <tibble [12 × 4]>
#>  4 Angola      Africa    <tibble [12 × 4]>
#>  5 Argentina   Americas  <tibble [12 × 4]>
#>  6 Australia   Oceania   <tibble [12 × 4]>
#>  7 Austria     Europe    <tibble [12 × 4]>
#>  8 Bahrain     Asia      <tibble [12 × 4]>
#>  9 Bangladesh  Asia      <tibble [12 × 4]>
#> 10 Belgium     Europe    <tibble [12 × 4]>
#> # … with 132 more rows

Copy Link

Version

Install

install.packages('repurrrsive')

Monthly Downloads

6,188

Version

1.1.0

License

CC0

Issues

Pull Requests

Stars

Forks

Maintainer

Jennifer Bryan

Last Published

December 17th, 2022

Functions in repurrrsive (1.1.0)

wesanderson_json

Path to wesanderson JSON and XML
gmaps_cities

Geocoded cities from Google Maps
got_chars_json

Paths to Game of Thrones data as JSON and XML
gh_users_json

Paths to GitHub data as JSON and XML
discog_json

Path to Discogs data as JSON
got_chars

Game of Thrones POV characters
discog

Sharla Gelfand's music collection
gh_users

GitHub users
gh_repos

GitHub repos
gap_simple

Gapminder data frame in various forms
repurrrsive-package

repurrrsive: Examples of Recursive Lists and Nested or Split Data Frames
wesanderson

Color palettes from Wes Anderson movies
sw_people

Entities from the Star Wars Universe