Giter Club home page Giter Club logo

repurrrsive's Introduction

CRAN status R-CMD-check Codecov test coverage

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("pak")
pak::pak("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

repurrrsive's People

Contributors

cwickham avatar hadley avatar jennybc avatar stufield avatar yaogithub2018 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

repurrrsive's Issues

working with recursively stored spatial data

Your call for examples made me realize I need purrr for table-fying the new sf classes.

Warning, this is not extensively tested, and I only look at polygons below (not lines or multi-points), but I think a purrr/dplyr-friendly illustration to open up the fortify black box is worth exploring.

In sp, data are stored as a list of list of matrices, and ggplot2 has fortify methods to convert it to long table form.

library(sp)
library(rgdal)
library(raster)
spdf <- shapefile(system.file("shapes/sids.shp", package="maptools"))

library(ggplot2)
ff <- fortify(spdf)
ggplot(ff) + aes(x = long, y = lat, group = group, fill = id) + geom_polygon() + geom_path() + guides(fill = FALSE)

The underlying ggplot2:::fortify.Polygons method, applied by ggplot2:::fortify.SpatialPolygons and ggplot2:::fortify.SpatialPolygonsDataFrame is a bit obscure.

We can achieve the same with purrr mapping (though we get slightly different fill due to the changed ID sorting).

library(purrr)
 pm <- bind_rows(map(spdf@polygons, function(x) bind_rows(map(x@Polygons, function(y) as.data.frame(y@coords)), .id = "part")), .id = "feature")
## part must be unique
pm <- pm %>% mutate(part = paste(part, feature, sep = "-"))
ggplot(pm) + aes(x = V1, y = V2, group = part, fill = feature) + geom_polygon() + geom_path() +  guides(fill = FALSE)

We can apply a similar approach to the new sf classes, and it's a fair bit simpler.

library(sf)  ## new!  on CRAN

## more or less the same dataset
nc <- st_read(system.file("gpkg/nc.gpkg", package="sf"), "nc.gpkg", crs = 4267)
nc_geom_long <- bind_rows(map(nc$geom, function(x) bind_rows(map(x, as.data.frame), .id = "part")), .id = "feature")
## part must be unique
nc_geom_long <- nc_geom_long %>% mutate(part = paste(part, feature, sep = "-"))
## here the names are X1/X2 rather than V1/V2 but it's not really relevant
ggplot(nc_geom_long) +  aes(x = X1, y = X2, group = part, fill = feature) + geom_polygon() + geom_path() +  guides(fill = FALSE)

Submit to CRAN

I think I might submit repurrrsive to CRAN in the next couple of days, in case it comes up in my upcoming talks or workshops.

@cwickham do you have any thoughts? Stuff you want to tweak, add, whatever?

GoT POV characters: books vs povBooks

Arya has zero books. Seems like an error, but whatever.

In some ways this is good for the package, because you have to deal with a field that is not equally present for all characters, i.e. it queues up the need for .default in purrr mapping functions. But brings up the point that perhaps povBooks is really what you want.

Move `master` branch to `main`

Cc @jennybc

The master branch of this repository will soon be renamed to main, as part of a coordinated change across several GitHub organizations (including, but not limited to: tidyverse, r-lib, tidymodels, and sol-eng). We anticipate this will happen by the end of September 2021.

That will be preceded by a release of the usethis package, which will gain some functionality around detecting and adapting to a renamed default branch. There will also be a blog post at the time of this master --> main change.

The purpose of this issue is to:

  • Help us firm up the list of targetted repositories
  • Make sure all maintainers are aware of what's coming
  • Give us an issue to close when the job is done
  • Give us a place to put advice for collaborators re: how to adapt

message id: entire_lizard

Release repurrrsive 1.0.0

Prepare for release:

  • devtools::check()
  • devtools::check_win_devel()
  • rhub::check_for_cran()
  • revdepcheck::revdep_check(num_workers = 4)
  • Polish NEWS
  • Polish pkgdown reference index
  • Draft blog post

Submit to CRAN:

  • usethis::use_version('major')
  • Update cran-comments.md
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • usethis::use_github_release()
  • usethis::use_dev_version()
  • Finish blog post
  • Tweet
  • Add link to blog post in pkgdown news menu

Level up the `discog` dataset

I merged #15 which brought in @sharlagelfand's discography.

That includes the script that makes the object and the object itself.

But I think this object still needs some attention in, e.g., tests and some coverage in README, in order to be brought up to a level closer to the other datasets. I don't think we necessarily need to go to extremes, like converting it to XML. But we should do the parts that are easy.

Upkeep for repurrrsive

2023

Necessary:

  • Update copyright holder in DESCRIPTION: person(given = "Posit Software, PBC", role = c("cph", "fnd"))
  • Update email addresses *@rstudio.com -> *@posit.co
  • Update logo (https://github.com/rstudio/hex-stickers); run use_tidy_logo()
  • usethis::use_tidy_coc()
  • usethis::use_tidy_github_actions()

Optional:

  • Review 2022 checklist to see if you completed the pkgdown updates
  • Prefer pak::pak("org/pkg") over devtools::install_github("org/pkg") in README
  • Consider running use_tidy_dependencies() and/or replace compat files with use_standalone()
  • use_standalone("r-lib/rlang", "types-check") instead of home grown argument checkers
  • Change files ending in .r to .R in R/ and/or tests/testthat/
  • Add alt-text to pictures, plots, etc; see https://posit.co/blog/knitr-fig-alt/ for examples

Release repurrrsive 1.1.0

Prepare for release:

  • git pull
  • Check current CRAN check results
  • Check if any deprecation processes should be advanced, as described in Gradual deprecation
  • Polish NEWS
  • urlchecker::url_check()
  • devtools::build_readme()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • rhub::check_for_cran()
  • revdepcheck::revdep_check(num_workers = 4)
  • Update cran-comments.md
  • git push
  • Draft blog post

Submit to CRAN:

  • usethis::use_version('minor')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • git push
  • usethis::use_github_release()
  • usethis::use_dev_version()
  • git push
  • Finish blog post
  • Tweet
  • Add link to blog post in pkgdown news menu

Upkeep for repurrrsive

Pre-history

  • usethis::use_readme_rmd()
  • usethis::use_roxygen_md()
  • usethis::use_github_links()
  • usethis::use_pkgdown_github_pages()
  • usethis::use_tidy_github_labels()
  • usethis::use_tidy_style()
  • usethis::use_tidy_description()
  • urlchecker::url_check()

2020

  • usethis::use_package_doc()
    Consider letting usethis manage your @importFrom directives here.
    usethis::use_import_from() is handy for this.
  • usethis::use_testthat(3) and upgrade to 3e, testthat 3e vignette
  • Align the names of R/ files and test/ files for workflow happiness.
    The docs for usethis::use_r() include a helpful script.
    usethis::rename_files() may be be useful.

2021

  • usethis::use_tidy_dependencies()
  • usethis::use_tidy_github_actions() and update artisanal actions to use setup-r-dependencies
  • Remove check environments section from cran-comments.md
  • Bump required R version in DESCRIPTION to 3.5
  • Use lifecycle instead of artisanal deprecation messages, as described in Communicate lifecycle changes in your functions

2022

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.