test <- function(data, variable, range, fill) {
# no quotes around {{ variable }}
# use :=
tmp <- data %>% complete({{ variable }} := range, fill = fill)
return(tmp)
}
# And the way I want to call the function:
z %>% test(g1, 1:5, fill = list(n = 0, gender = 'f'))
# A tibble: 5 × 3
g1 gender n
<dbl> <chr> <dbl>
1 1 f 0
2 2 f 3
3 3 f 2
4 4 f 8
5 5 f 3
tidyeval
is definitely weird to get used to, but it starts to make sense with practice.
You can find a tidyeval cheatsheet (PDF) from here