It used curly braces to reference the variables v1 and v2 within the function:
tab_freq <- function(data, v1, v2) {
data %>%
tabyl({{ v1 }}, {{ v2 }}) %>%
adorn_totals(c("row", "col")) %>%
adorn_percentages("all") %>%
adorn_pct_formatting(2) %>%
adorn_ns() # no need to print here
}
I was definitely happy to find the solution. However, I have found no references or documentation for this {{}} convention anywhere on the web. Could someone please refer me to any documentation on referencing variables in this way? So far the attached web link is the only place I've seen this.
Yes you are right, there could be a {{{ }}} but I think !!! enquos is less frequent.
About simple, I had this kind of splicing in mind (dummy example)
library(dplyr)
#>
#> Attachement du package : 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
# splice list
new_col <- list(
a = TRUE,
b = FALSE,
c = NA
)
tibble(A = rnorm(10)) %>%
mutate(!!!new_col)
#> # A tibble: 10 x 4
#> A a b c
#> <dbl> <lgl> <lgl> <lgl>
#> 1 -1.09 TRUE FALSE NA
#> 2 1.19 TRUE FALSE NA
#> 3 0.206 TRUE FALSE NA
#> 4 0.632 TRUE FALSE NA
#> 5 -0.711 TRUE FALSE NA
#> 6 1.74 TRUE FALSE NA
#> 7 0.779 TRUE FALSE NA
#> 8 1.21 TRUE FALSE NA
#> 9 0.583 TRUE FALSE NA
#> 10 -0.709 TRUE FALSE NA