Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use renv for package and R version management #36

Merged
merged 12 commits into from
Dec 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Rprofile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source("renv/activate.R")
4 changes: 2 additions & 2 deletions R/00_base_join.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ plot_data_join <- function(x, title = "", xlims = xlim(0.5, 5.5), ylims = ylim(-
}

# Data ----
x <- data_frame(
x <- tibble(
id = 1:3,
x = paste0("x", 1:3)
)

y <- data_frame(
y <- tibble(
id = (1:4)[-3],
y = paste0("y", (1:4)[-3])
)
Expand Down
16 changes: 9 additions & 7 deletions R/02_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,11 @@ plot_data <- function(x, title = "") {
coord_equal() +
ggtitle(title) +
theme_void() +
theme(plot.title = element_text(family = "Fira Mono", hjust = 0.5, size = 24)) +
guides(fill = FALSE)
theme(
plot.title = element_text(family = "Fira Mono", hjust = 0.5, size = 24),
plot.background = element_rect(fill = "white", color = "white")
) +
guides(fill = "none")
}

animate_plot <- function(x, transition_length = 2, state_length = 1) {
Expand All @@ -96,13 +99,12 @@ animate_plot <- function(x, transition_length = 2, state_length = 1) {
ease_aes("sine-in-out")
}

save_static_plot <- function(g, filename, formats = c("png", "svg")) {
filenames <- formats %>%
save_static_plot <- function(g, filename, formats = c("png", "svg"), ...) {
ggsave <- purrr::partial(ggplot2::ggsave, plot = g, ...)
formats %>%
purrr::set_names() %>%
purrr::map_chr(static_plot_filename, x = filename) %>%
purrr::iwalk(
~ ggsave(filename = .x, plot = g, dev = .y)
)
purrr::iwalk(~ ggsave(filename = .x, device = .y))
}

static_plot_filename <- function(x, ext) {
Expand Down
10 changes: 7 additions & 3 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ knitr::opts_chunk$set(

Garrick Aden-Buie -- [&commat;grrrck](https://twitter.com/grrrck) -- [garrickadenbuie.com](https://www.garrickadenbuie.com). Set operations contributed by [Tyler Grant Smith](https://github.com/TylerGrantSmith).

[![Binder](http://mybinder.org/badge.svg)](https://mybinder.org/v2/gh/gadenbuie/tidy-animated-verbs/main?urlpath=rstudio)
[![CC0](https://img.shields.io/badge/license_(images)_-CC0-green.svg)](https://creativecommons.org/publicdomain/zero/1.0/)
[![MIT](https://img.shields.io/badge/license_(code)_-MIT-green.svg)](https://opensource.org/licenses/MIT)

Expand Down Expand Up @@ -331,7 +330,7 @@ setdiff(y, x)

Many of the tools in the [tidyverse] expect data to be formatted as a tidy dataset and the [tidyr] package provides functions to help you organize your data into tidy data.

```{r tidyr-wide-long}
```{r tidyr-wide-long, fig.width = 6, fig.height = 10}
source("R/tidyr_spread_gather.R")

tidy_plots <- list()
Expand All @@ -346,7 +345,12 @@ tidy_plots <- map(tidy_plots, ~ mutate(.,

tidy_plots$wide <- tidy_plots$wide + ylim(-6.5, 0.5)

save_static_plot(cowplot::plot_grid(plotlist = tidy_plots, axis = "t"), "original-dfs-tidy")
save_static_plot(
patchwork::wrap_plots(tidy_plots, widths = 4, heights = 8),
width = 8,
height = 8,
"original-dfs-tidy"
)
```

![](images/static/png/original-dfs-tidy.png)
Expand Down
99 changes: 49 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,32 @@

Garrick Aden-Buie – [@grrrck](https://twitter.com/grrrck) –
[garrickadenbuie.com](https://www.garrickadenbuie.com). Set operations
contributed by [Tyler Grant
Smith](https://github.com/TylerGrantSmith).
contributed by [Tyler Grant Smith](https://github.com/TylerGrantSmith).

[![Binder](http://mybinder.org/badge.svg)](https://mybinder.org/v2/gh/gadenbuie/tidy-animated-verbs/main?urlpath=rstudio)
[![CC0](https://img.shields.io/badge/license_\(images\)_-CC0-green.svg)](https://creativecommons.org/publicdomain/zero/1.0/)
[![MIT](https://img.shields.io/badge/license_\(code\)_-MIT-green.svg)](https://opensource.org/licenses/MIT)
[![CC0](https://img.shields.io/badge/license_(images)_-CC0-green.svg)](https://creativecommons.org/publicdomain/zero/1.0/)
[![MIT](https://img.shields.io/badge/license_(code)_-MIT-green.svg)](https://opensource.org/licenses/MIT)

<!-- README START -->

- [**Mutating Joins**](#mutating-joins) —
- [**Mutating Joins**](#mutating-joins) —
[`inner_join()`](#inner-join), [`left_join()`](#left-join),
[`right_join()`](#right-join), [`full_join()`](#full-join)

- [**Filtering Joins**](#filtering-joins) —
- [**Filtering Joins**](#filtering-joins) —
[`semi_join()`](#semi-join), [`anti_join()`](#anti-join)

- [**Set Operations**](#set-operations) — [`union()`](#union),
- [**Set Operations**](#set-operations) — [`union()`](#union),
[`union_all()`](#union-all), [`intersect()`](#intersection),
[`setdiff()`](#set-difference)

- [**Tidy Data**](#tidy-data) — [`spread()` and
- [**Tidy Data**](#tidy-data) — [`spread()` and
`gather()`](#spread-and-gather)

- Learn more about
- [Using the animations and images](#usage)
- [Relational Data](#relational-data)
- [gganimate](#gganimate)
- Learn more about

- [Using the animations and images](#usage)
- [Relational Data](#relational-data)
- [gganimate](#gganimate)

## Background

Expand All @@ -48,7 +46,7 @@ Currently, the animations cover the [dplyr two-table
verbs](https://dplyr.tidyverse.org/articles/two-table.html) and I’d like
to expand the animations to include more verbs from the tidyverse.
[Suggestions are
welcome\!](https://github.com/gadenbuie/tidy-animated-verbs/issues)
welcome!](https://github.com/gadenbuie/tidy-animated-verbs/issues)

### Relational Data

Expand All @@ -74,11 +72,12 @@ excellent (and quick) introduction to gganimate.

### Dynamic Animations

Thanks to an initial push by [David Zimmermann](https://github.com/DavZim), we
have begun work toward a packaged set of functions to generate dynamic
explanatory animations from users' actual data.
Please visit the [pkg branch](https://github.com/gadenbuie/tidyexplain/tree/pkg)
of the tidyexplain repository for more information (or to contribute!).
Thanks to an initial push by [David
Zimmermann](https://github.com/DavZim), we have begun work towards
functions that generate dynamic animations from users’ actual data.
Please visit the [pkg
branch](https://github.com/gadenbuie/tidyexplain/tree/pkg) of the
tidyexplain repository for more information (or to contribute!).

## Mutating Joins

Expand All @@ -92,14 +91,14 @@ of the tidyexplain repository for more information (or to contribute!).

``` r
x
#> # A tibble: 3 x 2
#> # A tibble: 3 × 2
#> id x
#> <int> <chr>
#> 1 1 x1
#> 2 2 x2
#> 3 3 x3
y
#> # A tibble: 3 x 2
#> # A tibble: 3 × 2
#> id y
#> <int> <chr>
#> 1 1 y1
Expand All @@ -116,7 +115,7 @@ y

``` r
inner_join(x, y, by = "id")
#> # A tibble: 2 x 3
#> # A tibble: 2 × 3
#> id x y
#> <int> <chr> <chr>
#> 1 1 x1 y1
Expand All @@ -132,7 +131,7 @@ inner_join(x, y, by = "id")

``` r
left_join(x, y, by = "id")
#> # A tibble: 3 x 3
#> # A tibble: 3 × 3
#> id x y
#> <int> <chr> <chr>
#> 1 1 x1 y1
Expand All @@ -149,15 +148,15 @@ left_join(x, y, by = "id")

``` r
y_extra # has multiple rows with the key from `x`
#> # A tibble: 4 x 2
#> # A tibble: 4 × 2
#> id y
#> <dbl> <chr>
#> 1 1 y1
#> 2 2 y2
#> 3 4 y4
#> 4 2 y5
left_join(x, y_extra, by = "id")
#> # A tibble: 4 x 3
#> # A tibble: 4 × 3
#> id x y
#> <dbl> <chr> <chr>
#> 1 1 x1 y1
Expand All @@ -175,7 +174,7 @@ left_join(x, y_extra, by = "id")

``` r
right_join(x, y, by = "id")
#> # A tibble: 3 x 3
#> # A tibble: 3 × 3
#> id x y
#> <int> <chr> <chr>
#> 1 1 x1 y1
Expand All @@ -192,7 +191,7 @@ right_join(x, y, by = "id")

``` r
full_join(x, y, by = "id")
#> # A tibble: 4 x 3
#> # A tibble: 4 × 3
#> id x y
#> <int> <chr> <chr>
#> 1 1 x1 y1
Expand All @@ -219,7 +218,7 @@ full_join(x, y, by = "id")

``` r
semi_join(x, y, by = "id")
#> # A tibble: 2 x 2
#> # A tibble: 2 × 2
#> id x
#> <int> <chr>
#> 1 1 x1
Expand All @@ -235,7 +234,7 @@ semi_join(x, y, by = "id")

``` r
anti_join(x, y, by = "id")
#> # A tibble: 1 x 2
#> # A tibble: 1 × 2
#> id x
#> <int> <chr>
#> 1 3 x3
Expand All @@ -255,14 +254,14 @@ anti_join(x, y, by = "id")

``` r
x
#> # A tibble: 3 x 2
#> # A tibble: 3 × 2
#> x y
#> <chr> <chr>
#> 1 1 a
#> 2 1 b
#> 3 2 a
y
#> # A tibble: 2 x 2
#> # A tibble: 2 × 2
#> x y
#> <chr> <chr>
#> 1 1 a
Expand All @@ -277,26 +276,26 @@ y

``` r
union(x, y)
#> # A tibble: 4 x 2
#> # A tibble: 4 × 2
#> x y
#> <chr> <chr>
#> 1 2 b
#> 2 2 a
#> 3 1 b
#> 4 1 a
#> 1 1 a
#> 2 1 b
#> 3 2 a
#> 4 2 b
```

![](images/union-rev.gif)

``` r
union(y, x)
#> # A tibble: 4 x 2
#> # A tibble: 4 × 2
#> x y
#> <chr> <chr>
#> 1 2 a
#> 2 1 b
#> 3 2 b
#> 4 1 a
#> 1 1 a
#> 2 2 b
#> 3 1 b
#> 4 2 a
```

### Union All
Expand All @@ -307,7 +306,7 @@ union(y, x)

``` r
union_all(x, y)
#> # A tibble: 5 x 2
#> # A tibble: 5 × 2
#> x y
#> <chr> <chr>
#> 1 1 a
Expand All @@ -325,7 +324,7 @@ union_all(x, y)

``` r
intersect(x, y)
#> # A tibble: 1 x 2
#> # A tibble: 1 × 2
#> x y
#> <chr> <chr>
#> 1 1 a
Expand All @@ -340,7 +339,7 @@ intersect(x, y)

``` r
setdiff(x, y)
#> # A tibble: 2 x 2
#> # A tibble: 2 × 2
#> x y
#> <chr> <chr>
#> 1 1 b
Expand All @@ -351,7 +350,7 @@ setdiff(x, y)

``` r
setdiff(y, x)
#> # A tibble: 1 x 2
#> # A tibble: 1 × 2
#> x y
#> <chr> <chr>
#> 1 2 b
Expand All @@ -375,13 +374,13 @@ you organize your data into tidy data.

``` r
wide
#> # A tibble: 2 x 4
#> # A tibble: 2 × 4
#> id x y z
#> <int> <chr> <chr> <chr>
#> 1 1 a c e
#> 2 2 b d f
long
#> # A tibble: 6 x 3
#> # A tibble: 6 × 3
#> id key val
#> <int> <chr> <chr>
#> 1 1 x a
Expand Down Expand Up @@ -410,7 +409,7 @@ long

``` r
gather(wide, key, val, x:z)
#> # A tibble: 6 x 3
#> # A tibble: 6 × 3
#> id key val
#> <int> <chr> <chr>
#> 1 1 x a
Expand All @@ -420,7 +419,7 @@ gather(wide, key, val, x:z)
#> 5 1 z e
#> 6 2 z f
spread(long, key, val)
#> # A tibble: 2 x 4
#> # A tibble: 2 × 4
#> id x y z
#> <int> <chr> <chr> <chr>
#> 1 1 a c e
Expand Down
13 changes: 13 additions & 0 deletions deps.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Don't source this file, it's just used to tell {renv} which packages we need
library(tidyverse)
library(rmarkdown)
library(markdown)
library(here)
library(patchwork)
library(sysfonts)
library(jsonlite)
library(curl)
library(showtext)
library(gganimate)
library(gifski)
library(svglite)
Binary file modified images/anti-join.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/full-join.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/inner-join.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/intersect.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/left-join-extra.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/left-join.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/right-join.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/semi-join.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/setdiff-rev.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/setdiff.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/static/png/anti-join.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/static/png/full-join.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/static/png/inner-join.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/static/png/intersect.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/static/png/left-join-extra-input.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/static/png/left-join-extra.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/static/png/left-join.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/static/png/original-dfs-set-ops.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/static/png/original-dfs-tidy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/static/png/original-dfs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/static/png/right-join.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/static/png/semi-join.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/static/png/setdiff-rev.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/static/png/setdiff.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/static/png/tidyr-gather.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/static/png/tidyr-spread.png
Binary file modified images/static/png/union-all.png
Binary file modified images/static/png/union-rev.png
Binary file modified images/static/png/union.png
Loading