Skip to content

Commit 394246a

Browse files
committed
Update use dm package vignette
1 parent 75bac6f commit 394246a

File tree

2 files changed

+175
-21
lines changed

2 files changed

+175
-21
lines changed

vignettes/use_dm.Rmd

+78-21
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,22 @@ Because all of the tables created in {pixarfilms} are connected by each film,
1919
this gives an interesting opportunity to explore these interconnected tables
2020
together.
2121

22-
```{r, include = FALSE}
23-
knitr::opts_chunk$set(
24-
collapse = TRUE,
25-
comment = "#>"
26-
)
27-
```
22+
2823

2924

3025
## Setup
3126

32-
```{r setup}
27+
28+
```r
3329
library(dm)
30+
library(pixarfilms)
3431
```
3532

3633

3734
## Setup
3835

39-
```{r}
36+
37+
```r
4038
# Create dm object
4139
dm <- dm(pixar_films, pixar_people, academy, box_office, genres, public_response, pixar_rankings)
4240

@@ -46,9 +44,9 @@ dm <-
4644
dm_add_pk(pixar_films, film) %>%
4745
dm_add_pk(academy, c(film, award_type)) %>%
4846
dm_add_pk(box_office, film) %>%
49-
dm_add_pk(genres, c(film, category)) %>%
50-
dm_add_pk(public_response, film) %>%
51-
dm_add_pk(pixar_rankings, c(film, source))
47+
dm_add_pk(genres, c(film, category, value)) %>%
48+
# dm_add_pk(pixar_rankings, c(film, source)) %>%
49+
dm_add_pk(public_response, film)
5250

5351
# Create foreign keys
5452
dm <-
@@ -57,8 +55,8 @@ dm <-
5755
dm_add_fk(academy, film, pixar_films) %>%
5856
dm_add_fk(box_office, film, pixar_films) %>%
5957
dm_add_fk(genres, film, pixar_films) %>%
60-
dm_add_fk(public_response, film, pixar_films) %>%
61-
dm_add_fk(pixar_rankings, film, pixar_films)
58+
# dm_add_fk(pixar_rankings, film, pixar_films) %>%
59+
dm_add_fk(public_response, film, pixar_films)
6260

6361
# Add splash of color
6462
dm <-
@@ -73,25 +71,84 @@ dm <-
7371

7472
## Explore
7573

76-
```{r}
74+
75+
```r
7776
dm
77+
#> ── Metadata ───────────────────────────────────────────────────────────────────────────────────
78+
#> Tables: `pixar_films`, `pixar_people`, `academy`, `box_office`, `genres`, … (7 total)
79+
#> Columns: 31
80+
#> Primary keys: 5
81+
#> Foreign keys: 5
7882
```
7983

80-
```{r}
84+
85+
```r
8186
dm %>%
8287
dm_examine_cardinalities()
88+
#> • FK: pixar_people$(`film`) -> pixar_films$(`film`): surjective mapping (child: 1 to n -> parent: 1)
89+
#> • FK: academy$(`film`) -> pixar_films$(`film`): surjective mapping (child: 1 to n -> parent: 1)
90+
#> • FK: box_office$(`film`) -> pixar_films$(`film`): bijective mapping (child: 1 -> parent: 1)
91+
#> • FK: genres$(`film`) -> pixar_films$(`film`): surjective mapping (child: 1 to n -> parent: 1)
92+
#> • FK: public_response$(`film`) -> pixar_films$(`film`): bijective mapping (child: 1 -> parent: 1)
8393
```
8494

8595

86-
```{r}
96+
97+
```r
8798
dm %>%
8899
dm_examine_constraints()
100+
#> ℹ All constraints satisfied.
89101
```
90102

91103

92-
## Visualize connections
93-
94-
```{r}
95-
dm_draw(dm)
104+
## System information
105+
106+
107+
```r
108+
sessionInfo()
109+
#> R version 4.0.4 (2021-02-15)
110+
#> Platform: aarch64-unknown-linux-gnu (64-bit)
111+
#> Running under: Debian GNU/Linux 11 (bullseye)
112+
#>
113+
#> Matrix products: default
114+
#> BLAS: /usr/lib/aarch64-linux-gnu/blas/libblas.so.3.9.0
115+
#> LAPACK: /usr/lib/aarch64-linux-gnu/lapack/liblapack.so.3.9.0
116+
#>
117+
#> locale:
118+
#> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8
119+
#> [4] LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
120+
#> [7] LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C
121+
#> [10] LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
122+
#>
123+
#> attached base packages:
124+
#> [1] stats graphics grDevices utils datasets methods base
125+
#>
126+
#> other attached packages:
127+
#> [1] pixarfilms_1.0.0 dm_1.0.10 ggbeeswarm_0.7.2 irr_0.84.1
128+
#> [5] lpSolve_5.6.22 scales_1.3.0 votesys_0.1.1 gghighlight_0.4.1
129+
#> [9] ggrepel_0.9.6 forcats_1.0.0 purrr_1.0.2 tibble_3.2.1
130+
#> [13] ggplot2_3.5.0 tidyverse_2.0.0 reticulate_1.39.0 knitr_1.46
131+
#> [17] gtrendsR_1.5.1.9000 httr_1.4.7 rvest_1.0.4 fuzzyjoin_0.1.6
132+
#> [21] tidyr_1.3.1 dplyr_1.1.4 stringr_1.5.1 readr_2.1.5
133+
#> [25] progress_1.2.3 lubridate_1.9.3 usethis_3.0.0 janitor_2.2.0
134+
#> [29] here_1.0.1
135+
#>
136+
#> loaded via a namespace (and not attached):
137+
#> [1] fs_1.6.3 webshot_0.5.5 RColorBrewer_1.1-3 rprojroot_2.0.4
138+
#> [5] tools_4.0.4 backports_1.4.1 utf8_1.2.4 R6_2.5.1
139+
#> [9] vipor_0.4.7 DBI_1.2.2 colorspace_2.1-0 withr_3.0.0
140+
#> [13] tidyselect_1.2.1 prettyunits_1.2.0 compiler_4.0.4 cli_3.6.2
141+
#> [17] xml2_1.3.6 digest_0.6.35 rmarkdown_2.28 pkgconfig_2.0.3
142+
#> [21] htmltools_0.5.8.1 sessioninfo_1.2.2 dbplyr_2.5.0 fastmap_1.2.0
143+
#> [25] htmlwidgets_1.6.4 rlang_1.1.3 rstudioapi_0.16.0 shiny_1.9.1
144+
#> [29] visNetwork_2.1.2 generics_0.1.3 jsonlite_1.8.8 gtools_3.9.5
145+
#> [33] magrittr_2.0.3 Matrix_1.3-2 Rcpp_1.0.12 munsell_0.5.1
146+
#> [37] fansi_1.0.6 lifecycle_1.0.4 stringi_1.8.3 yaml_2.3.8
147+
#> [41] snakecase_0.11.1 grid_4.0.4 promises_1.3.0 crayon_1.5.2
148+
#> [45] lattice_0.20-41 hms_1.1.3 pillar_1.9.0 igraph_2.0.3
149+
#> [49] glue_1.7.0 evaluate_0.23 data.table_1.15.4 png_0.1-8
150+
#> [53] vctrs_0.6.5 tzdb_0.4.0 httpuv_1.6.15 gtable_0.3.4
151+
#> [57] cachem_1.1.0 xfun_0.43 mime_0.12 xtable_1.8-4
152+
#> [61] later_1.3.2 beeswarm_0.4.0 memoise_2.0.1 timechange_0.3.0
153+
#> [65] DiagrammeR_1.0.11
96154
```
97-

vignettes/use_dm.Rmd.orig

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
title: "Using pixarfilms with dm"
3+
description: |
4+
Explore how to us the dm package with pixarfilms data.
5+
output: rmarkdown::html_vignette
6+
vignette: >
7+
%\VignetteIndexEntry{Using pixarfilms with dm}
8+
%\VignetteEngine{knitr::rmarkdown}
9+
%\VignetteEncoding{UTF-8}
10+
---
11+
12+
## Overview
13+
14+
The {pixarfilms} R package has been added to the {dm} R package, which is a
15+
package "for working with multiple related tables, stored as data frames or in a
16+
relational database."
17+
18+
Because all of the tables created in {pixarfilms} are connected by each film,
19+
this gives an interesting opportunity to explore these interconnected tables
20+
together.
21+
22+
```{r, include = FALSE}
23+
knitr::opts_chunk$set(
24+
collapse = TRUE,
25+
comment = "#>"
26+
)
27+
```
28+
29+
30+
## Setup
31+
32+
```{r setup}
33+
library(dm)
34+
library(pixarfilms)
35+
```
36+
37+
38+
## Setup
39+
40+
```{r}
41+
# Create dm object
42+
dm <- dm(pixar_films, pixar_people, academy, box_office, genres, public_response, pixar_rankings)
43+
44+
# Create primary keys
45+
dm <-
46+
dm %>%
47+
dm_add_pk(pixar_films, film) %>%
48+
dm_add_pk(academy, c(film, award_type)) %>%
49+
dm_add_pk(box_office, film) %>%
50+
dm_add_pk(genres, c(film, category, value)) %>%
51+
# dm_add_pk(pixar_rankings, c(film, source)) %>%
52+
dm_add_pk(public_response, film)
53+
54+
# Create foreign keys
55+
dm <-
56+
dm %>%
57+
dm_add_fk(pixar_people, film, pixar_films) %>%
58+
dm_add_fk(academy, film, pixar_films) %>%
59+
dm_add_fk(box_office, film, pixar_films) %>%
60+
dm_add_fk(genres, film, pixar_films) %>%
61+
# dm_add_fk(pixar_rankings, film, pixar_films) %>%
62+
dm_add_fk(public_response, film, pixar_films)
63+
64+
# Add splash of color
65+
dm <-
66+
dm %>%
67+
dm_set_colors(
68+
`#5B9BD5` = pixar_films,
69+
`#ED7D31` = c(academy, box_office, genres, public_response),
70+
`#70AD47` = pixar_people
71+
)
72+
```
73+
74+
75+
## Explore
76+
77+
```{r}
78+
dm
79+
```
80+
81+
```{r}
82+
dm %>%
83+
dm_examine_cardinalities()
84+
```
85+
86+
87+
```{r}
88+
dm %>%
89+
dm_examine_constraints()
90+
```
91+
92+
93+
## System information
94+
95+
```{r}
96+
sessionInfo()
97+
```

0 commit comments

Comments
 (0)