Created
February 13, 2021 05:20
-
-
Save shannonpileggi/2be5c3c45740144245e20eff4a4ab20b to your computer and use it in GitHub Desktop.
A demonstration of the walrus operator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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