0

I use the inline statement in Rmarkdown from the gtsummary package. However, I get a strange result when I use it with a certain variable !!

The problem happens when a variable and a level of the variable have the same level. Here is problem demonstrated with the trial data frame that comes with the package.

var_label(trial) <- list(trt = "Drug A")
tbl1 <- trial %>% 
    select(trt) %>%
    tbl_summary()
inline_text(tbl1, variable = trt, level = "Drug A")

it results in:

[1] NA         "98 (49%)"

Any idea why this is happening?

Here is my very minimalistic YAML:

title: "hello"
author: "ebay"
date: "3/5/2021"

and my setup chunk:

library(gtsummary)
knitr::opts_chunk$set(error = F, echo = F, warning = F, fig.width=6.3, fig.height=4.5, fig.align = "center")
ebay
  • 109
  • 1
  • 7
  • I downloaded your dataset, and ran this code with no error. Can you please put your code into a proper reprex and update your question? Here's a guide on creating a minimal reproducible example https://community.rstudio.com/t/faq-how-to-do-a-minimal-reproducible-example-reprex-for-beginners/23061 – Daniel D. Sjoberg Mar 06 '21 at 15:32
  • @DanielD.Sjoberg Thanks for looking into this question. Great package btw. I have updated my question. The problem still occurs even in the reprex data frame. – ebay Mar 06 '21 at 15:50
  • Thanks! Can you review this document on creating a reprex using the reprex package and update your post with a reproducible example? You can use `dput(head(df))` to copy and paste a small version of your dataset to the example. – Daniel D. Sjoberg Mar 06 '21 at 15:58
  • I should have been more explanatory in my comment. I am happy to assist, but because the code runs correctly on my machine, I'll need to see the example in a full and proper reprex to continue looking at it. There is something happening that is not replicating, and the full preprex environment can help us diagnose. – Daniel D. Sjoberg Mar 06 '21 at 16:30
  • Hi @DanielD.Sjoberg. I think I figured out why this is happening. Please read the question again. I have updated everything. On a another matter: I found out that using `column=stat_0` can be used in `inline` in tables stratified by a variable with an overall value. May be it's worth adding this in the gtsummary documentation. Really useful package. Thank you. – ebay Mar 06 '21 at 21:55
  • Ahhh, yes, I hadn't considered that the variable label and the variable's levels would be the same when I wrote the function! Hmmmm, I am not sure what the best solution is, and I'll need to think about it. Sometimes users need to select the first row (the variable label row) to print p-values, and others they need to select the levels (like in your example). For the time being, you'll need to ensure they are different to use inline text. An alternative is to access the internal tibble of results yourself and extract the statistic you need, e.g. `tbl1$table_body`. – Daniel D. Sjoberg Mar 06 '21 at 22:14
  • https://github.com/ddsjoberg/gtsummary/issues/814 FYI – Daniel D. Sjoberg Mar 06 '21 at 22:20
  • I don't think it's a problem i can solve given the current infrastructure, but I can add messaging to make it clear why it's happening – Daniel D. Sjoberg Mar 06 '21 at 22:24

1 Answers1

1

The labels of the variable and its levels shouldn't be 100% identical.

ebay
  • 109
  • 1
  • 7