Hi everyone,
I'ts my first contact with the janitor and rlang packages.
I try to do a for loop with janitor and rlang but something is wrong, I don´t know what happend please help me to fix it.
My session info
version version R version 3.6.0 (2019-04-26)
os os Windows >= 8 x64
system system i386, mingw32
Packages' version:
dplyr * 0.8.2 2019-06-29 [1] CRAN (R 3.6.0)
janitor * 1.2.0 2019-04-21 [1] CRAN (R 3.6.0)
rlang * 0.4.0 2019-06-25 [1] CRAN (R 3.6.0)
First of all I make a simple code with janitor's function all fine:
prueba <- mtcars %>%
tabyl(am,cyl) %>%
adorn_totals(c("row", "col")) %>%
adorn_percentages("all") %>%
adorn_pct_formatting() %>%
adorn_ns(position = "front")
I saw the @mara ´s account in Twitter reply the rlang's new version and I would like to prove this and I mix janitor and rlang packages
(tab_freq <- function(data, v1, v2) {
data %>%
tabyl({{ v1 }}, {{ v2 }}) %>%
adorn_totals(c("row", "col")) %>%
adorn_percentages("all") %>%
adorn_pct_formatting() %>%
adorn_ns(position = "front") %>%
print()
})
tab_freq(mtcars, am, cyl)
Good, I did it
But why not make a for loop with this?
And make something like this...
for(i in seq2(1,10)){
prim <- names(mtcars)[i]
secun <- names(mtcars)[i+1]
(tab_freq(mtcars,{{prim}},{{secun}}))
}
Oh boy, what the...?
I don´t know how can I fix it
Error: Strings must match column names. Unknown columns: cyl Call rlang::last_error()
to see a backtrace