Learn R Programming

crosstable (version 0.3.2)

as_flextable.crosstable: Turns a crosstable object into a formatted flextable

Description

These objects are imported from other packages. Follow the links below to see their documentation.

flextable

as_flextable

Usage

# S3 method for crosstable
as_flextable(
  x,
  keep_id = FALSE,
  by_header = NULL,
  autofit = TRUE,
  compact = FALSE,
  show_test_name = TRUE,
  fontsizes = list(body = 11, subheaders = 11, header = 11),
  padding_v = NULL,
  remove_header_keys = FALSE,
  header_show_n = FALSE,
  generic_labels = list(id = ".id", variable = "variable", value = "value", total =
    "Total", label = "label", test = "test", effect = "effect"),
  ...
)

Arguments

x

the result of crosstable()

keep_id

whether to keep the .id column

by_header

a string to override the by header

autofit

whether to use flextable::autofit() on the table

compact

whether to compact the table

show_test_name

in the test column, show the test name

fontsizes

font sizes as a list of keys c(body, subheaders, header). If set through arguments instead of options, all 3 names should be specified.

padding_v

vertical padding (body)

remove_header_keys

if TRUE and x has several by strata, header will only display values

header_show_n

show the size (N=xx) of each terminal by strata in their header

generic_labels

names of the crosstable default columns. Useful for translation for instance.

...

unused

Value

a flextable

Methods (by class)

  • crosstable: Turns a crosstable object into a formatted flextable.

See Also

crosstable(), flextable::flextable(), as_gt.crosstable()

Examples

Run this code
# NOT RUN {
#Crosstables
library(crosstable)
library(dplyr)
crosstable_options(crosstable_fontsize_header=14, 
                   crosstable_fontsize_subheaders=10, 
                   crosstable_fontsize_body=8)
crosstable(iris) %>% as_flextable()
crosstable(mtcars2, by=c(am, vs)) %>% as_flextable()
crosstable(mtcars2, cols=c(mpg, cyl), by=am, effect=TRUE) %>% 
   as_flextable(keep_id=TRUE, autofit=FALSE)
crosstable(mtcars2, cols=c(mpg, cyl), by=am, effect=TRUE) %>% 
   as_flextable(compact=TRUE)

#Renaming (because why not?)
crosstable(mtcars2, by=vs, total="both", test=TRUE, effect=TRUE) %>%
   rename(ID=.id, math=variable, Tot=Total, lab=label, pval=test, fx=effect) %>%
   as_flextable(by_header = "Engine shape", 
                generic_labels=list(id = "ID", variable = "math", total="Tot", 
                                    label = "lab", test = "pval", effect="fx"))
# }

Run the code above in your browser using DataLab