How could I pass what columns should adorn_totals
consider without passing another arguments.
library(dplyr)
library(janitor)
mtcars %>%
count(vs,am) %>%
adorn_totals()
#> vs am n
#> 0 0 12
#> 0 1 6
#> 1 0 7
#> 1 1 7
#> Total 2 32
I don't want the total in column "AM" to be calculated, only in column "n". I know I can do this by passing the column names at the end of the function, but to do this you have to pass through all the other arguments first adorn_totals(,,,, n)
, which is ugly.
Is there any way to do this directly, as in:
mtcars %>%
count(vs,am) %>%
adorn_totals(... = n)
#> Error in `adorn_totals()`:
#> ! Names can't be of the form `...` or `..j`.
#> ✖ These names are invalid:
#> * "..." at location 1.
#> Backtrace:
#> ▆
#> 1. ├─mtcars %>% count(vs, am) %>% adorn_totals(... = n)
#> 2. └─janitor::adorn_totals(., ... = n)
#> 3. └─tidyselect::eval_select(expr, data = dat)
#> 4. └─tidyselect:::eval_select_impl(...)
#> 5. ├─tidyselect:::with_subscript_errors(...)
#> 6. │ └─rlang::try_fetch(...)
#> 7. │ └─base::withCallingHandlers(...)
#> 8. └─tidyselect:::vars_select_eval(...)
#> 9. └─tidyselect:::ensure_named(...)
#> 10. └─vctrs::vec_as_names(names(pos), repair = "check_unique", call = call)
#> 11. └─vctrs (local) `<fn>`()
#> 12. └─vctrs:::validate_unique(names = names, arg = arg, call = call)
#> 13. └─vctrs:::stop_names_cannot_be_dot_dot(names, call = call)
#> 14. └─vctrs:::stop_names(...)
#> 15. └─vctrs:::stop_vctrs(...)
#> 16. └─rlang::abort(message, class = c(class, "vctrs_error"), ..., call = vctrs_error_call(call))
As a hack you could give that argument a name that isn't otherwise in the named arguments for adorn_totals
. That is:
mtcars %>%
count(vs,am) %>%
adorn_totals(cols=n)
vs am n
0 0 12
0 1 6
1 0 7
1 1 7
Total - 32