1

I have updated R studio and all packages including gt summary. I didn't change my script. But now in every row the following "?" appears enter image description here

conflict_prefer("trial", "gtsummary")
library(tidyverse)
head(trial)

table <- 
  tbl_summary(
    trial,
    by = trt, # split table by group
    missing = "no" # don't list missing data separately
  ) %>%
  add_n() %>% # add column with total number of non-missing observations
  add_p() %>% # test for a difference between groups
  modify_header(label = "**Variable**") %>% # update the column header
  bold_labels()

The session info reports enter image description here enter image description here

Maybe this is not connected to gtsummary. Can anyone help, how to solve this problem?

Thank you very much

gideon1321
  • 51
  • 1
  • 5
  • 1
    Hi! I know can seem to be a lot of work, but if you can post a small dataset and a minimal function that produces this, it would be much easier to help you :) see [here](https://stackoverflow.com/a/5963610/11856430). it's probably an encoding problem. Please also post the outcome of your `sessionInfo()` – Leon Samson Oct 08 '22 at 10:17
  • 1
    Thanks Leon. Of course, I have added a example. Is this the correct sessionInfo(). I appreciate every help – gideon1321 Oct 08 '22 at 11:35
  • Thank you! I cannot reproduce it on my windows computer unfortunately so it must have to do with the local settings. See also [here](https://stackoverflow.com/a/15276232/11856430), its probably an encoding issue/ Where do you run the code, in Rstudio? Please restart, run the example with only packages `dplyr` and `gtsummary` attached (nothing else), and again print the `sessionInfo()`. It will reduce the attached packages, and should show info about R version, platform (windows 10 for example), and locale (info like this: `LC_COLLATE=English_United Kingdom.utf8`) – Leon Samson Oct 08 '22 at 12:08
  • 1
    Not sure if it works, but you can try something like this: `Sys.setlocale(locale = "English_United Kingdom.utf8")`. It will depend on your settings. UTF-8 encoding is what should work usually. – Leon Samson Oct 08 '22 at 12:30
  • Dear Leon, dear Daniel, thank you so much for all your help. I am very grateful. I do not have experience with gutHib. Following your advise regarding local settings, I have removed all packages, deinstalled R-Studio and "R" and re-installed the programs/packages. Now everything is fine. Thanks a lot to both of you. GTsummary is such a great package!!! – gideon1321 Oct 09 '22 at 10:32

1 Answers1

0

Leon is correct. It seems you have an encoding issue on your machine that is not rendering the unicode U-00A0 character correctly. I would investigate your local setting, or reach out on the {gt} GitHub page about a resolution.

In the meantime, you can implement one of these solutions to get your tables working now.

  1. Any {gtsummary} table can be exported as gt, flextable, huxtable, kableExtra, kable, or even to just a tibble. For example, you can convert your table to flextable with table %>% as_flex_table(). Review the following page for more details: https://www.danieldsjoberg.com/gtsummary/articles/rmarkdown.html

  2. If (and only if) you are using HTML output, you can implement indentation using gt::tab_style(). You would first need to remove all indentation from your gtsummary table, then convert to a gt table, then implement indentation via gt::tab_style(). Example below

library(gtsummary)

table <- 
  trial %>%
  tbl_summary(include = grade) %>%
  modify_table_styling(
    columns = label,
    text_format = "indent",
    undo_text_format = TRUE
  ) %>%
  as_gt() %>%
  gt::tab_style(
    style = gt::cell_text(indent = gt::px(10), align = "left"),
    locations = gt::cells_body(
      columns = label,
      rows = row_type == "level"
    )
  )
Daniel D. Sjoberg
  • 8,820
  • 2
  • 12
  • 28