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

by in tbl_summary fails if passed column named "variable" #1234

Closed
berg-michael opened this issue May 3, 2022 · 3 comments · Fixed by #1235
Closed

by in tbl_summary fails if passed column named "variable" #1234

berg-michael opened this issue May 3, 2022 · 3 comments · Fixed by #1235
Milestone

Comments

@berg-michael
Copy link

Hi,

I've noticed that using the by argument in tbl_summary won't work if the column I am summarizing by is named "variable". I'm assuming this is some kind of parsing issue. Things work fine when I change the variable name to group, see reprex below. I haven't taken a close look as to why this might be occurring. Thought an issue may be relevant as the default output of data.table's melt function (from wide to long) includes a column entitled variable.

library(gtsummary)


df <- data.frame(group = c(rep("A", 5), rep("B", 5)), value= 1:10)

tbl1 <- df |> 
  tbl_summary(
  by = "group"
)


df <- data.frame(variable = c(rep("A", 5), rep("B", 5)), value= 1:10)

tbl2 <- df |> 
  tbl_summary(
  by = "variable"
)
#> Error in `mutate()`:
#> ! Problem while computing `df_stats = pmap(...)`.
#> Caused by error in `set_names()`:
#> ! The size of `nm` (2) must be compatible with the size of `x` (1).

Created on 2022-05-03 by the reprex package (v2.0.1)

@ddsjoberg
Copy link
Owner

Thank you so much for the reprex and the bug report. I used the column name variable SO much within the internals....it's surely an issue with one too many columns running around named variable.

Depending on how tricky it is to fix, I may just add a check that the by variable is not named variable for the time being.

@ddsjoberg
Copy link
Owner

Thank you for the report @berg-michael ! Luckily it was an easy fix :)

@berg-michael
Copy link
Author

Of course, thank you taking the time to fix it!

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

Successfully merging a pull request may close this issue.

2 participants