Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gadenbuie/starwarsdb
Relational Data from the Star Wars API for Learning and Teaching
https://github.com/gadenbuie/starwarsdb
dplyr duckdb-database learning relational-database sql star-wars-data teaching
Last synced: 3 months ago
JSON representation
Relational Data from the Star Wars API for Learning and Teaching
- Host: GitHub
- URL: https://github.com/gadenbuie/starwarsdb
- Owner: gadenbuie
- License: other
- Created: 2020-10-07T19:38:05.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-12-08T16:08:54.000Z (about 2 years ago)
- Last Synced: 2024-07-04T02:34:41.825Z (6 months ago)
- Topics: dplyr, duckdb-database, learning, relational-database, sql, star-wars-data, teaching
- Language: R
- Homepage: https://pkg.garrickadenbuie.com/starwarsdb
- Size: 584 KB
- Stars: 37
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
- awesome-rainmana - gadenbuie/starwarsdb - Relational Data from the Star Wars API for Learning and Teaching (R)
- jimsghstars - gadenbuie/starwarsdb - Relational Data from the Star Wars API for Learning and Teaching (R)
README
---
output: github_document
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```[swapi]: https://swapi.dev
[rwars]: https://github.com/Ironholds/rwars
[dbplyr]: https://dbplyr.tidyverse.org/
[dm]: https://krlmlr.github.io/dm/
[duckdb]: https://duckdb.org# starwarsdb
[![CRAN status](https://www.r-pkg.org/badges/version/starwarsdb)](https://CRAN.R-project.org/package=starwarsdb)
[![R-CMD-check](https://github.com/gadenbuie/starwarsdb/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/gadenbuie/starwarsdb/actions/workflows/R-CMD-check.yaml)**starwarsdb** provides data from the [Star Wars API][swapi] as a set of relational tables, or as an in-package [DuckDB] database.
![](man/figures/README-starwars-data-model-1.svg)
**Formats:**
[Metadata](#star-wars-data),
[Local Tables](#local-tables),
[Remote Tables](#remote-tables),
[Data Model (dm)](#dm-tables),
[API (rwars)](#api)## Installation
You can install **starwarsdb** from CRAN:
``` r
install.packages("starwarsdb")
```Or you can install the development version of **starwarsdb** from GitHub with [remotes](https://remotes.r-lib.org):
``` r
# install.packages("remotes")remotes::install_github("gadenbuie/starwarsdb")
# For remotes <= 2.1.0
remotes::install_github("gadenbuie/starwarsdb@main")
```## Star Wars Data
```{r echo=FALSE}
library(tibble)
```All of the tables are available when you load **starwarsdb**
```{r message=FALSE, warning=FALSE}
library(dplyr)
library(starwarsdb)
```or via
```{r eval=FALSE}
data(package = "starwarsdb")
```The `schema` table includes information about the tables that were sourced from [SWAPI].
```{r}
schema
``````{r}
schema %>%
filter(endpoint == "films") %>%
pull(properties)
```## Local Tables
Ask questions, like _who flew an X-Wing?_
```{r}
x_wing_pilots <- pilots %>% filter(vehicle == "X-wing")
x_wing_pilotspeople %>% semi_join(x_wing_pilots, by = c(name = "pilot"))
```## Remote Tables
**starwarsdb** also includes the entire data set as a DuckDB database,
appropriate for teaching and practicing remote database access with [dbplyr].```{r}
con <- starwars_connect()people_rmt <- tbl(con, "people")
pilots_rmt <- tbl(con, "pilots")
pilots_rmtx_wing_pilots <- pilots_rmt %>% filter(vehicle == "X-wing")
x_wing_pilotspeople_rmt %>% semi_join(x_wing_pilots, by = c(name = "pilot"))
```## DM Tables
Finally, **starwarsdb** provides a function that returns a pre-configured [dm] object.
The `dm` package wraps local data frames into a complete relational data model.```{r dm-tables}
library(dm, warn.conflicts = FALSE)sw_dm <- starwars_dm()
sw_dmsw_dm %>%
dm_select_tbl(pilots, people) %>%
dm_filter(pilots = vehicle == "X-wing") %>%
dm_zoom_to("people") %>%
semi_join(pilots)
``````{r starwars-data-model, eval = FALSE, echo = TRUE}
dm_draw(sw_dm)
```![](man/figures/README-starwars-data-model-1.svg)
```{r starwars-data-model-write, echo = FALSE, eval = TRUE}
sw_dm %>%
dm_draw(graph_attrs = 'bgcolor="transparent"', node_attrs = 'fontname="Helvetica"') %>%
DiagrammeRsvg::export_svg() %>%
writeLines("man/figures/README-starwars-data-model-1.svg")
```## API
For API access from R, check out the [rwars] package by Oliver Keyes.
Big thanks to `rwars` for making it easy to access the Star Wars API!