Test with a new {dplyr} version

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

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-108")

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

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

renv::snapshot()

To demonstrate package dependency control, I’ve installed {dplyr} version 1.0.8 for this post, which is the current version and includes the across() function introduced in version 1.0.0.

I’ve written another post that uses an older version (0.8.5) of {dplyr} to prove that the dependencies don’t conflict.

Proof

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

[1] '1.0.8'
any(grepl("across", ls("package:dplyr")))
[1] TRUE

Demo

This means we can use across(), rather than {dplyr}’s old approach of the *_if(), *_at() and *_all() variants of verbs like mutate() and summarise().

Here’s a very small example.

palmerpenguins::penguins %>% 
  select(where(is.factor)) %>% 
  mutate(across(c(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