flextable (version 0.5.6)

as_flextable: method to convert object to flextable

Description

This is a convenient function to let users create flextable bindings from any objects.

Usage

as_flextable(x, ...)

# S3 method for grouped_data as_flextable(x, col_keys = NULL, hide_grouplabel = FALSE, ...)

Arguments

x

object to be transformed as flextable

...

arguments for custom methods

col_keys

columns names/keys to display. If some column names are not in the dataset, they will be added as blank columns by default.

hide_grouplabel

if TRUE, group label will not be rendered, only level/value will be rendered.

Examples

Run this code
# NOT RUN {
# as_flextable and as_grouped_data -----
if( require("magrittr")){
  library(data.table)
  CO2 <- CO2
  setDT(CO2)
  CO2$conc <- as.integer(CO2$conc)

  data_co2 <- dcast(CO2, Treatment + conc ~ Type,
                    value.var = "uptake", fun.aggregate = mean)
  data_co2 <- as_grouped_data(x = data_co2, groups = c("Treatment"))

  zz <- as_flextable( data_co2 ) %>%
    add_footer_lines("dataset CO2 has been used for this flextable") %>%
    add_header_lines("mean of carbon dioxide uptake in grass plants") %>%
    set_header_labels(conc = "Concentration") %>%
    autofit() %>%
    width(width = c(1, 1, 1))
  zz
}
# }

Run the code above in your browser using DataCamp Workspace