Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adorn_total("col") still skips first column even when numeric #285

Closed
sydanny opened this issue Apr 16, 2019 · 1 comment
Closed

adorn_total("col") still skips first column even when numeric #285

sydanny opened this issue Apr 16, 2019 · 1 comment

Comments

@sydanny
Copy link

sydanny commented Apr 16, 2019

When adorning columns with a total (adorn_totals("col")), the first column is always skipped, even if it is numeric.

df <- tibble::tribble(
    ~ a, ~ b,
      1,   2,
      3,   4
  )
df %>% adorn_totals("col")

Output:

df
# A tibble: 2 x 2
      a     b
  <dbl> <dbl>
1     1     2
2     3     4

df %>% adorn_totals("col")
 a b Total
 1 2     2
 3 4     4

Expected output:

df %>% adorn_totals("col")
 a b Total
 1 2     3
 3 4     7

This was reported as an old issue that was fixed, but here it appears to still be broken. (#57)

@sfirke
Copy link
Owner

sfirke commented Apr 17, 2019

Thanks for filing this! I had to re-acquaint myself with this. I agree that it would be better if this was a more flexible function in terms of column specification. Right now ?adorn_totals notes:

This function excludes the first column of the input data.frame, assuming it's a descriptive variable not to be summed.

And I think it has to work that way currently because:


mtcars %>%
  tabyl(cyl, gear) %>%
  glimpse()

Observations: 3
Variables: 4
$ cyl <dbl> 4, 6, 8
$ `3` <dbl> 1, 2, 12
$ `4` <dbl> 8, 4, 0
$ `5` <dbl> 2, 1, 2

If adorn_totals("col") summed that first numeric column, it would be wrong. So I can't just switch it to sum all numeric columns.

A longer-term solution would be to allow for column selection like dplyr::select(), then you could say whether to sum that first numeric column. This issue is discussed in #219 so I'll close this to keep discussion in one place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants