Set width of first 'terms' column in r arsenal tableby

Viewed 117

I'd like to limit the width of the first 'terms' column in an arsenal::tableby summary table. I know that I can achieve it by using the as.data.frame(width = xx) command followed by a call to knitr::kable, but then I lose all the rest of the column formatting (eg. alignment).

I'd like to knit the table in an html and/or latex document.


library(arsenal)
library(dplyr, warn.conflicts = FALSE)

data(mockstudy)
tab1 <- tableby(arm ~ sex + age, data=mockstudy, digits = 0)


mylabels <- list(
  sex = "This is a really long title that I want to wrap", 
  age ="Age, yrs")
summary(tab1, labelTranslations = mylabels, text=TRUE)
#> 
#> 
#> |                                                | A: IFL (N=428) | F: FOLFOX (N=691) | G: IROX (N=380) | Total (N=1499) | p value|
#> |:-----------------------------------------------|:--------------:|:-----------------:|:---------------:|:--------------:|-------:|
#> |This is a really long title that I want to wrap |                |                   |                 |                |   0.190|
#> |-  Male                                         |  277 (64.7%)   |    411 (59.5%)    |   228 (60.0%)   |  916 (61.1%)   |        |
#> |-  Female                                       |  151 (35.3%)   |    280 (40.5%)    |   152 (40.0%)   |  583 (38.9%)   |        |
#> |Age, yrs                                        |                |                   |                 |                |   0.614|
#> |-  Mean (SD)                                    |    60 (11)     |      60 (12)      |     60 (11)     |    60 (12)     |        |
#> |-  Range                                        |    27 - 88     |      19 - 88      |     26 - 85     |    19 - 88     |        |

summary(tab1, labelTranslations = mylabels, text=TRUE) %>% 
  as.data.frame(width = 20) %>% 
  knitr::kable(format = "markdown")

#>
#>|                  |A: IFL (N=428) |F: FOLFOX (N=691) |G: IROX (N=380) |Total (N=1499) |p value |
#>|:-----------------|:--------------|:-----------------|:---------------|:--------------|:-------|
#>|This is a really  |               |                  |                |               |0.190   |
#>|long title that I |               |                  |                |               |        |
#>|want to wrap      |               |                  |                |               |        |
#>|-  Male           |277 (64.7%)    |411 (59.5%)       |228 (60.0%)     |916 (61.1%)    |        |
#>|-  Female         |151 (35.3%)    |280 (40.5%)       |152 (40.0%)     |583 (38.9%)    |        |
#>|Age, yrs          |               |                  |                |               |0.614   |
#>|-  Mean (SD)      |60 (11)        |60 (12)           |60 (11)         |60 (12)        |        |
#>|-  Range          |27 - 88        |19 - 88           |26 - 85         |19 - 88        |        |

0 Answers
Related