Created
September 21, 2022 11:53
-
-
Save charliejhadley/47f123256d392b569fc3c33ec3d436ac to your computer and use it in GitHub Desktop.
tidyeval-names-glue.R
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) | |
fn_with_tidyeval_glue <- function(.data, target_column){ | |
chr_target_column <- quo_name(enquo(target_column)) | |
pvw_glue <- paste0("{", chr_target_column, "}_{.value}") | |
.data %>% | |
pivot_wider( | |
names_from = {{target_column}}, | |
names_glue = pvw_glue, | |
values_from = c(estimate, moe) | |
) | |
} | |
us_rent_income %>% | |
fn_with_tidyeval_glue(variable) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment