dcomtois / summarytools

R Package to Quickly and Neatly Summarize Data
523 stars 78 forks source link

tb(descr(...)) doesn't work with a grouping variable named 'method' #127

Closed cmrnp closed 4 years ago

cmrnp commented 4 years ago

Hi,

The tb() method fails with an error when given the output of descr() from a grouped tibble where the grouping variable is named 'method' (or 'decreasing'). The same code works correctly for other variable names. See below code as a minimal example to reproduce:

dat <- tibble(method = c("new", "old"), outcome = c(1, 2))

# produces: Error in match.arg(method) : 'arg' must be of length 1
dat %>%
  group_by(method) %>%
  descr(outcome) %>%
  tb()

# produces expected output
dat %>%
  rename(not_method = method) %>%
  group_by(not_method) %>%
  descr(outcome) %>%
  tb()

I think this can be fixed by putting unname() around the second argument to do.call(what = "order", ...) (in two places).

Cheers,

Cam

dcomtois commented 4 years ago

Thanks for the update @cmrnp !