-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
75bac6f
commit 394246a
Showing
2 changed files
with
175 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
--- | ||
title: "Using pixarfilms with dm" | ||
description: | | ||
Explore how to us the dm package with pixarfilms data. | ||
output: rmarkdown::html_vignette | ||
vignette: > | ||
%\VignetteIndexEntry{Using pixarfilms with dm} | ||
%\VignetteEngine{knitr::rmarkdown} | ||
%\VignetteEncoding{UTF-8} | ||
--- | ||
|
||
## Overview | ||
|
||
The {pixarfilms} R package has been added to the {dm} R package, which is a | ||
package "for working with multiple related tables, stored as data frames or in a | ||
relational database." | ||
|
||
Because all of the tables created in {pixarfilms} are connected by each film, | ||
this gives an interesting opportunity to explore these interconnected tables | ||
together. | ||
|
||
```{r, include = FALSE} | ||
knitr::opts_chunk$set( | ||
collapse = TRUE, | ||
comment = "#>" | ||
) | ||
``` | ||
|
||
|
||
## Setup | ||
|
||
```{r setup} | ||
library(dm) | ||
library(pixarfilms) | ||
``` | ||
|
||
|
||
## Setup | ||
|
||
```{r} | ||
# Create dm object | ||
dm <- dm(pixar_films, pixar_people, academy, box_office, genres, public_response, pixar_rankings) | ||
|
||
# Create primary keys | ||
dm <- | ||
dm %>% | ||
dm_add_pk(pixar_films, film) %>% | ||
dm_add_pk(academy, c(film, award_type)) %>% | ||
dm_add_pk(box_office, film) %>% | ||
dm_add_pk(genres, c(film, category, value)) %>% | ||
# dm_add_pk(pixar_rankings, c(film, source)) %>% | ||
dm_add_pk(public_response, film) | ||
|
||
# Create foreign keys | ||
dm <- | ||
dm %>% | ||
dm_add_fk(pixar_people, film, pixar_films) %>% | ||
dm_add_fk(academy, film, pixar_films) %>% | ||
dm_add_fk(box_office, film, pixar_films) %>% | ||
dm_add_fk(genres, film, pixar_films) %>% | ||
# dm_add_fk(pixar_rankings, film, pixar_films) %>% | ||
dm_add_fk(public_response, film, pixar_films) | ||
|
||
# Add splash of color | ||
dm <- | ||
dm %>% | ||
dm_set_colors( | ||
`#5B9BD5` = pixar_films, | ||
`#ED7D31` = c(academy, box_office, genres, public_response), | ||
`#70AD47` = pixar_people | ||
) | ||
``` | ||
|
||
|
||
## Explore | ||
|
||
```{r} | ||
dm | ||
``` | ||
|
||
```{r} | ||
dm %>% | ||
dm_examine_cardinalities() | ||
``` | ||
|
||
|
||
```{r} | ||
dm %>% | ||
dm_examine_constraints() | ||
``` | ||
|
||
|
||
## System information | ||
|
||
```{r} | ||
sessionInfo() | ||
``` |