79151071

Date: 2024-11-02 16:24:40
Score: 0.5
Natty:
Report link
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

Reasons:
  • RegEx Blacklisted phrase (1): I want
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: gabagool