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

Making the headers much nicer in the tables #9256

Open
lilyclements opened this issue Nov 14, 2024 · 0 comments
Open

Making the headers much nicer in the tables #9256

lilyclements opened this issue Nov 14, 2024 · 0 comments

Comments

@lilyclements
Copy link
Contributor

Should be a very small one if @Patowhiz and @rdstern agree!

Currently, if we run the tab_spanner_delim in the tables dialogs, then it automatically splits by "". This is ok, but it might cause issues if a user naturally has an "" in their variable name, or might cause issues if you want to split by a summary when it is something like "non_count_missing".

This can be fixed very easily by changing the separator in R. We just need the separator in the pivot_wider to be the same as in tab_spanner_delim. I want to suggest we do a small fix like "XXXXX", but this is assuming that no one would ever use "XXXXX" in their column headers! Is there a suggestion of what we can put in here?

E.g., we have this at the moment (except we don't call names_sep = "_" in pivot_wider as that's the default):

summary_table <- data_book$summary_table(data_name="survey", columns_to_summarise=c("size","fert","yield"), factors=c("village","variety","fertgrp"), treat_columns_as_factor=TRUE, summaries=c("summary_mean", "summary_count_non_missing"), drop = FALSE)

pivoted_table <- summary_table %>% tidyr::pivot_wider(names_from = c("village", "summary"),
                                                      values_from = value,
                                                      names_sort = TRUE,
                                                      names_sep = "_")

pivoted_table %>%
                 gt::gt() %>%
                 gt::tab_spanner_delim(delim = "_")

giving

image

If we set that separator to be a string, then we will not have this issue. E.g., if I generate a random 16 digit code, we can tell thet separator to be 8wu7sldpo9et7ydb

summary_table <- data_book$summary_table(data_name="survey", columns_to_summarise=c("size","fert","yield"), factors=c("village","variety","fertgrp"), treat_columns_as_factor=TRUE, summaries=c("summary_mean", "summary_count_non_missing"), drop = FALSE)

pivoted_table <- summary_table %>% tidyr::pivot_wider(names_from = c("village", "summary"),
                                                      values_from = value,
                                                      names_sort = TRUE,
                                                      names_sep = "8wu7sldpo9et7ydb")

pivoted_table %>%
                 gt::gt() %>%
                 gt::tab_spanner_delim(delim = "8wu7sldpo9et7ydb")

image

This is a very easy fix! We just need to:

  1. Add in names_sep = "8wu7sldpo9et7ydb" in the pivot_wider
  2. Change delim = "_" to delim = "8wu7sldpo9et7ydb" in the tab_spanner_delim

@Patowhiz @rdstern thoughts?

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

No branches or pull requests

1 participant