Function converts a gtsummary object to a tibble.

# S3 method for gtsummary
as_tibble(
  x,
  include = everything(),
  col_labels = TRUE,
  return_calls = FALSE,
  fmt_missing = FALSE,
  ...
)

# S3 method for gtsummary
as.data.frame(...)

Arguments

x

Object created by a function from the gtsummary package (e.g. tbl_summary or tbl_regression)

include

Commands to include in output. Input may be a vector of quoted or unquoted names. tidyselect and gtsummary select helper functions are also accepted. Default is everything().

col_labels

Logical argument adding column labels to output tibble. Default is TRUE.

return_calls

Logical. Default is FALSE. If TRUE, the calls are returned as a list of expressions.

fmt_missing

Logical argument adding the missing value formats.

...

Not used

Value

a tibble

See also

Other gtsummary output types: as_flex_table(), as_gt(), as_hux_table(), as_kable_extra(), as_kable()

Author

Daniel D. Sjoberg

Examples

# \donttest{
tbl <-
  trial %>%
  select(trt, age, grade, response) %>%
  tbl_summary(by = trt)

as_tibble(tbl)
#> # A tibble: 8 × 3
#>   `**Characteristic**` `**Drug A**, N = 98` `**Drug B**, N = 102`
#>   <chr>                <chr>                <chr>                
#> 1 Age                  46 (37, 59)          48 (39, 56)          
#> 2 Unknown              7                    4                    
#> 3 Grade                NA                   NA                   
#> 4 I                    35 (36%)             33 (32%)             
#> 5 II                   32 (33%)             36 (35%)             
#> 6 III                  31 (32%)             33 (32%)             
#> 7 Tumor Response       28 (29%)             33 (34%)             
#> 8 Unknown              3                    4                    

# without column labels
as_tibble(tbl, col_labels = FALSE)
#> # A tibble: 8 × 3
#>   label          stat_1      stat_2     
#>   <chr>          <chr>       <chr>      
#> 1 Age            46 (37, 59) 48 (39, 56)
#> 2 Unknown        7           4          
#> 3 Grade          NA          NA         
#> 4 I              35 (36%)    33 (32%)   
#> 5 II             32 (33%)    36 (35%)   
#> 6 III            31 (32%)    33 (32%)   
#> 7 Tumor Response 28 (29%)    33 (34%)   
#> 8 Unknown        3           4          
# }