Learn R Programming

ftExtra (version 0.2.0)

as_flextable_methods: method to convert object to flextable

Description

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

Usage

# S3 method for grouped_df
as_flextable(
  x,
  groups_to = c("titles", "merged", "asis"),
  groups_pos = c("left", "asis"),
  ...
)

# S3 method for data.frame as_flextable(x, col_keys = names(x), ...)

Arguments

x

object to be transformed as flextable

groups_to

One of titles, merged, or asis. See examples for the result.

groups_pos

When groups_to = "merged", grouping columns are reordered according to group_pos. Choices are left (default) or asis.

...

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.

See Also

Other as_flextable methods: as_flextable.gam(), as_flextable.glm(), as_flextable.grouped_data(), as_flextable.htest(), as_flextable.lm(), as_flextable.xtable()

Examples

Run this code
# NOT RUN {
# For grouped_df
grouped_df <- iris %>%
  dplyr::group_by(Species) %>%
  dplyr::slice(1, 2)

as_flextable(grouped_df, groups_to = "titles")
as_flextable(grouped_df, groups_to = "titles", hide_grouplabel = TRUE)
as_flextable(grouped_df, groups_to = "merged")
as_flextable(grouped_df, groups_to = "asis")
# For data.frame
iris %>%
  head() %>%
  as_flextable()
# }

Run the code above in your browser using DataLab