What is the tidyverse recommended style for quoting or not created variables by mutate or summarise?

Hi,

Is there a tidyverse recommended style for whether to quote or not the names of variables to be created by mutate or summarise?

library(palmerpenguins)
library(dplyr)

penguins %>% 
  transmute(body_mass_kg = body_mass_g / 1000) 

penguins %>% 
  transmute("body_mass_kg" = body_mass_g / 1000) 

penguins %>% 
  group_by(species) %>% 
  summarise("body_mass_g" = mean(body_mass_g, na.rm = T))

penguins %>% 
  group_by(species) %>% 
  summarise(body_mass_g = mean(body_mass_g, na.rm = T))

Similarly, when you use across and the c function, should you quote or not quote variables?

penguins %>% 
  transmute(across(c(species, island), ~str_to_sentence(.x)))

penguins %>% 
  transmute(across(c("species", "island"), ~str_to_sentence(.x)))

Thanks!
David

No quotes! If you want to refer to variables by a character string, you can use mutate_at.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.