Skip to content

Instantly share code, notes, and snippets.

@charliejhadley
Created September 21, 2022 11:53
Show Gist options
  • Save charliejhadley/47f123256d392b569fc3c33ec3d436ac to your computer and use it in GitHub Desktop.
Save charliejhadley/47f123256d392b569fc3c33ec3d436ac to your computer and use it in GitHub Desktop.
tidyeval-names-glue.R
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