Skip to content

Instantly share code, notes, and snippets.

@shannonpileggi
Created February 13, 2021 05:20
Show Gist options
  • Save shannonpileggi/2be5c3c45740144245e20eff4a4ab20b to your computer and use it in GitHub Desktop.
Save shannonpileggi/2be5c3c45740144245e20eff4a4ab20b to your computer and use it in GitHub Desktop.
A demonstration of the walrus operator
library(tidyverse)
library(rlang)
library(glue)
# string to append to variable name
suffix <- "A"
# example data frame
dat <- tibble(x = 1:5) %>%
# create new variable with walrus operator
mutate(
"x_{suffix}" := x
)
# view data
dat
# select newly named column
dat %>%
dplyr::select(glue::glue("x_{suffix}"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment