| Title: | Relational Data from the 'Star Wars' API for Learning and Teaching |
| Version: | 0.1.3 |
| Description: | Provides data about the 'Star Wars' movie franchise in a set of relational tables or as a complete 'DuckDB' database. All data was collected from the open source 'Star Wars' API. |
| License: | MIT + file LICENSE |
| URL: | https://github.com/gadenbuie/starwarsdb, https://pkg.garrickadenbuie.com/starwarsdb/ |
| BugReports: | https://github.com/gadenbuie/starwarsdb/issues |
| Depends: | R (≥ 2.10) |
| Imports: | DBI, duckdb, magrittr, tibble |
| Suggests: | dbplyr, dm, dplyr, testthat |
| Config/Needs/website: | any::DiagrammeR, any::DiagrammeRsvg, gadenbuie/grkgdown |
| Encoding: | UTF-8 |
| LazyData: | true |
| RoxygenNote: | 7.3.2 |
| NeedsCompilation: | no |
| Packaged: | 2025-08-22 16:56:48 UTC; garrick |
| Author: | Garrick Aden-Buie |
| Maintainer: | Garrick Aden-Buie <garrick@adenbuie.com> |
| Repository: | CRAN |
| Date/Publication: | 2025-08-23 00:10:02 UTC |
Relational Data from the Star Wars API for Learning and Teaching
Description
starwarsdb provides tables about the films, characters, planets and vehicles in the Star Wars movie franchise universe. The package and the tables have been organized to facilitate learning relational database concepts, like joins. It also includes functions that connect to a local DuckDB (file-based) database for teaching and practice working with remote databases via dplyr, DBI, and dm.
Tables
Author(s)
Maintainer: Garrick Aden-Buie garrick@adenbuie.com (ORCID)
References
The Star Wars API (SWAPI).
See Also
The rwars package by Oliver Keyes.
Pipe operator
Description
See magrittr::%>% for details.
Usage
lhs %>% rhs
Films
Description
Films in the Star Wars movie franchise.
Usage
films
Format
A data frame with 6 rows and 6 variables:
titleThe title of this film.
episode_idThe episode number of this film.
opening_crawlThe opening crawl text at the beginning of this film.
directorThe director of this film.
producerhe producer(s) of this film.
release_dateThe release date at original creator country.
References
The Star Wars API (SWAPI).
People in Films
Description
Links characters (people) to the films in which they appear.
Usage
films_people
Format
A data frame with 162 rows and 2 variables:
titleThe title of the film.
characterThe name of the character who appeared in the film.
References
The Star Wars API (SWAPI).
Planets in Films
Description
Links planets to the films in which they appear.
Usage
films_planets
Format
A data frame with 33 rows and 2 variables:
titleThe title of the film.
planetThe name of the planet that appeared in the film.
References
The Star Wars API (SWAPI).
Vehicles in Films
Description
Links vehicles to the films in which they appear
Usage
films_vehicles
Format
A data frame with 104 rows and 2 variables:
titleThe title of the film.
vehicleThe name of the vehicle that appeared in the film.
References
The Star Wars API (SWAPI).
People
Description
Characters within the Star Wars universe.
Usage
people
Format
A data frame with 82 rows and 10 variables:
nameThe name of this person.
heightThe height of this person in meters.
massThe mass of this person in kilograms.
hair_colorThe hair color of this person.
skin_colorThe skin color of this person.
eye_colorThe eye color of this person.
birth_yearThe birth year of this person. BBY (Before the Battle of Yavin) or ABY (After the Battle of Yavin).
sexThe biological sex of the character. One of
male,female,hermaphroditic, ornone.genderThe gender role or gender identity of the character.
homeworldThe planet the character was born on.
speciesThe species of the character.
References
The Star Wars API (SWAPI).
Pilots
Description
Links people to the vehicles they have piloted.
Usage
pilots
Format
A data frame with 43 rows and 2 variables:
pilotThe name of the person who piloted the vehicle.
vehicleThe name of the vehicle that was piloted.
References
The Star Wars API (SWAPI).
Planets
Description
Planets in the Star Wars universe.
Usage
planets
Format
A data frame with 59 rows and 9 variables:
nameThe name of this planet.
rotation_periodThe number of standard hours it takes for this planet to complete a single rotation on its axis.
orbital_periodThe number of standard days it takes for this planet to complete a single orbit of its local star.
diameterThe diameter of this planet in kilometers.
climateThe climate of this planet. Comma-seperated if diverse.
gravityA number denoting the gravity of this planet. Where 1 is normal.
terrainThe terrain of this planet. Comma-seperated if diverse.
surface_waterThe percentage of the planet surface that is naturally occurring water or bodies of water.
populationThe average population of sentient beings inhabiting this planet.
References
The Star Wars API (SWAPI).
Star Wars Data Schema
Description
Includes information about the schema of the tables that were sourced from
SWAPI, the Star Wars API. Not all properties returned from the API are
columns in the data in this package: some properties were refactored into
separate tables. For example, I combined the starships/ and vehicles/
endpoint into a single table. Both API endpoints returned a "pilots"
property, which is described in the schema as an array of people who piloted
the vehicle. The information in this property has been extracted into a
separate table called pilots in the starwarsdb package.
Usage
schema
Format
A data frame with 5 rows and 4 variables:
endpointThe name of the SWAPI endpoint.
endpoint_titleThe title of the SWAPI endpoint.
endpoint_descriptionThe description of the SWAPI endpoint.
propertiesThe properties of the endpoint as a nested table containing the
variable, the datatype, adescriptionand theformatof the property.
References
The Star Wars API (SWAPI).
Species
Description
Species within the Star Wars universe.
Usage
species
Format
A data frame with 37 rows and 10 variables:
nameThe name of this species.
classificationThe classification of this species.
designationThe designation of this species.
average_heightThe average height of this person in centimeters.
skin_colorsA comma-seperated string of common skin colors for this species, none if this species does not typically have skin.
hair_colorsA comma-seperated string of common hair colors for this species, none if this species does not typically have hair.
eye_colorsA comma-seperated string of common eye colors for this species, none if this species does not typically have eyes.
average_lifespanThe average lifespan of this species in years.
homeworldThe URL of a planet resource, a planet that this species originates from.
languageThe language commonly spoken by this species.
References
The Star Wars API (SWAPI).
Connect to the Star Wars Database
Description
Provides a connection to a DuckDB database of the Star Wars data.
Alternatively, you can use starwars_db() to manually connect to the
database using DBI::dbConnect() and duckdb::duckdb().
Usage
starwars_connect(dbdir = ":memory:", ...)
starwars_disconnect(con)
starwars_db()
Arguments
dbdir |
Location for database files. Should be a path to an existing
directory in the file system. With the default (or |
... |
Additional parameters passed to |
con |
A connection to the Star Wars database |
Value
A connection to the Star Wars database, or the path to the database.
Functions
-
starwars_connect(): Connect to the DuckDB database -
starwars_disconnect(): Disconnect from the DuckDB database -
starwars_db(): Returns the path to the starwarsdb database
Examples
# Manually connect using {duckdb} and {DBI}
con <- DBI::dbConnect(
duckdb::duckdb(),
dbdir = starwars_db(),
read_only = TRUE
)
if (requireNamespace("dplyr", quietly = TRUE)) {
dplyr::tbl(con, "films")
}
# Disconnect from that database (shutdown is specific to duckdb)
DBI::dbDisconnect(con, shutdown = TRUE)
# Or connect without worrying about connection details
con <- starwars_connect()
if (requireNamespace("dplyr", quietly = TRUE)) {
dplyr::tbl(con, "films")
}
# Similarly, disconnect quickly without worrying about duckdb arguments
starwars_disconnect(con)
Create a Star Wars Data Model Object
Description
Creates a dm object with the starwarsdb tables.
Usage
starwars_dm(configure_dm = TRUE, remote = FALSE)
starwars_dm_configure(dm)
Arguments
configure_dm |
If |
remote |
If |
dm |
A dm object with the starwarsdb tables |
Value
A dm object
Functions
-
starwars_dm_configure(): Configure the starwars dm object with primary and foreign keys and colors.
See Also
dm::dm(), dm::dm_add_pk(), dm::dm_add_fk(), dm::dm_from_src()
Examples
# If the {dm} package is installed...
if (requireNamespace("dm", quietly = TRUE)) {
# Create a full starwars {dm} object from local tables
starwars_dm(remote = TRUE)
# Create a base starwars {dm} object from remote tables wihout keys
starwars_dm(configure_dm = FALSE, remote = TRUE)
}
Starships or Vehicles
Description
A Starship or vehicle in the Star Wars universe.
Usage
vehicles
Format
A data frame with 75 rows and 14 variables:
nameThe name of this vehicle. The common name, such as Sand Crawler.
typeThe type of the vehicle: starship or vehicle.
classThe class of the vehicle, source from
starship_classorvehicle_class.modelThe model or official name of this vehicle. Such as All Terrain Attack Transport.
manufacturerThe manufacturer of this vehicle. Comma seperated if more than one.
cost_in_creditsThe cost of this vehicle new, in galactic credits.
lengthThe length of this vehicle in meters.
max_atmosphering_speedThe maximum speed of this vehicle in atmosphere.
crewThe number of personnel needed to run or pilot this vehicle.
passengersThe number of non-essential people this vehicle can transport.
cargo_capacityThe maximum number of kilograms that this vehicle can transport.
consumablesThe maximum length of time that this vehicle can provide consumables for its entire crew without having to resupply.
hyperdrive_ratingThe class of this starships hyperdrive.
MGLTThe Maximum number of Megalights this starship can travel in a standard hour. A Megalight is a standard unit of distance and has never been defined before within the Star Wars universe. This figure is only really useful for measuring the difference in speed of starships. We can assume it is similar to AU, the distance between our Sun (Sol) and Earth.
References
The Star Wars API (SWAPI).