Test with an old {dplyr} version

Rendering a post using a {renv} profile with {dplyr} version 0.8.5.

Matt Dray
2022-03-14

Set up

To generate this demo, I:

  1. Created this new post
  2. Activated a {renv} profile with a unique name
  3. Installed the packages needed for the post
  4. Captured the dependencies in the profile’s lockfile
distill::create_post("dplyr-085")

renv::activate(profile = "2022-03-14-dplyr-085")

renv::install(
  "distill",
  "rmarkdown",
  "palmerpenguins",
  "dplyr@0.8.5"
)

renv::snapshot()

To demonstrate package dependency control, I’ve installed {dplyr} version 0.8.5 for this post, which is the version before the across() function was introduced.

I’ve written another post that uses a newer version (1.0.8) of {dplyr} to prove that the dependencies don’t conflict.

Proof

We can prove the across() function doesn’t exist for the version of {dplyr} installed with the ‘2022-03-14-dplyr-085’ profile.

[1] '0.8.5'
any(grepl("across", ls("package:dplyr")))
[1] FALSE

Demo

This means we have to make do with {dplyr}’s old functionality for across(), which amounts to the *_if(), *_at() and *_all() variants of verbs like mutate() and summarise().

Here’s a very small example.

palmerpenguins::penguins %>% 
  select_if(is.factor) %>% 
  mutate_at(vars(species, island), tolower) %>% 
  head()
# A tibble: 6 × 3
  species island    sex   
  <chr>   <chr>     <fct> 
1 adelie  torgersen male  
2 adelie  torgersen female
3 adelie  torgersen female
4 adelie  torgersen <NA>  
5 adelie  torgersen female
6 adelie  torgersen male