dplyr
dplyr with bang bang example
Varying the name of the output variable
We need to do the following:
- Use quo_name() to convert the input expression to string
- Use := helper provided by rlang
# https://www.onceupondata.com/2017/08/12/my-first-steps-into-the-world-of-tidyeval/
<- function(x, cname, count_col){
add_tag_count
<- enquo(cname)
cname
<- enquo(count_col)
count_col <- quo_name(count_col)
count_col_name
%>%
x mutate(!!count_col_name := map_int(!!cname, length))
}
Capturing multiple variables
<- function(df, ..., percent = TRUE){
freq_tbl <- quos(...)
group
<- df %>%
out group_by(!!!group) %>%
summarise(freq = n()) %>%
arrange(desc(freq)) %>%
ungroup()
if(percent == TRUE){
<- out %>%
out mutate(percentage = 100*freq/sum(freq))
}return(out)
}