Hi @lionel,
This works really nicely for continuous outcomes, but not when I try to implement something similar for categorical outcomes, The issue is in the gather function, it seems to convert the values to character instead of preserving factors. So when you use complete it doesn't see the Value column as factor. (This is probably straying from the discussion around tidy evaluation though...)
library(tidyverse)
fac_mtcars <- mtcars %>%
mutate_at(vars(cyl,carb), as.factor) %>%
select(cyl, carb) %>%
as_tibble()
table(fac_mtcars$cyl, fac_mtcars$carb)
#>
#> 1 2 3 4 6 8
#> 4 5 6 0 0 0 0
#> 6 2 0 0 4 1 0
#> 8 0 4 3 6 0 1
## Doesn't honour the `complete` since Value is of type `character`
## rather than `factor`.
fac_mtcars %>%
group_by(cyl) %>%
gather("Variable", "Value", carb) %>%
group_by(Variable, add = TRUE) %>%
count(Value) %>%
complete(Value, fill=list(n=0))
#> # A tibble: 9 x 4
#> # Groups: cyl, Variable [3]
#> cyl Variable Value n
#> <fct> <chr> <chr> <dbl>
#> 1 4 carb 1 5
#> 2 4 carb 2 6
#> 3 6 carb 1 2
#> 4 6 carb 4 4
#> 5 6 carb 6 1
#> 6 8 carb 2 4
#> 7 8 carb 3 3
#> 8 8 carb 4 6
#> 9 8 carb 8 1
```
). I think tidy eval is particularly interesting when it's used in between some DSL (or other language) and R code.
