flex_print: flextable wrapper

View source: R/flex_print.R

flex_printR Documentation

flextable wrapper

Description

A wrapper function for flextable::flextable() with some of my preferred formatting for simple tables.

Usage

flex_print(
  x,
  font_name = "Arial",
  font_size = 11,
  align = NULL,
  align_j = NULL,
  auto_fit = TRUE,
  width = NULL,
  width_j = NULL,
  width_unit = "in",
  col_nms = NULL,
  col_lbls = NULL,
  title = NULL,
  subtitle = NULL,
  footer = NULL,
  title_size = 16,
  subtitle_size = 11,
  footer_size = 11,
  na_dflt = "NA",
  nan_dflt = "NaN"
)

Arguments

x

dataset

font_name

single character value, the font family name. With Word and PowerPoint output, the value specifies the font to be used to format characters in the Unicode range (U+0000-U+007F). For "all" table parts.

font_size

integer value (points). For "all" table parts.

align

Column alignment: a character vector consisting of 'l' (left), 'c' (center), 'r' (right), and/or 'j' (justify). By default or if align = NULL, numeric columns are right-aligned, and other columns are left-aligned. If length(align) == 1L, the string will be expanded to a vector of individual letters, e.g. 'clc' becomes c('c', 'l', 'c').

align_j

Column selection for align argument. Default is 1:length(align).

auto_fit

Logical (Default is FALSE). See flextable::autofit()

width

width in inches as a character vector.

width_j

columns selection for width.

width_unit

unit for width, one of "in", "cm", "mm".

col_nms

Names of columns to be labelled.

col_lbls

Labels to apply to columns different from column names.

title

The text for the title.

subtitle

The text for the subtitle which will be displayed below the title.

footer

The text for the footer which will be displayed below the body of the table.

title_size

Font size for the title. Default is 16.

subtitle_size

Font size for the subtitle. Default is 11.

footer_size

Font size for the footer Default is 11.

na_dflt, nan_dflt

string to be used for NA and NaN values.

Value

A flextable

Examples

flex_print(x = head(iris))

flex_print(x = head(iris),
           font_name = "Lato",
           title = "Edgar Anderson's Iris Data",
           title_size = 16,
           subtitle = "Just the head")

flex_print(x = head(iris),
           font_name = "Lato",
           title = "Edgar Anderson's Iris Data",
           title_size = 16)

flex_print(x = head(iris),
           font_name = "Times New Roman",
           title = "Edgar Anderson's Iris Data",
           title_size = 16,
           footer = "The data were collected by Anderson, Edgar (1935). The irises of the Gaspe Peninsula, Bulletin of the American Iris Society, 59, 2–5.")

flex_print(x = head(iris),
           align = c("c"),
           col_lbls = c("Sepal Length",
                        "Sepal Width",
                        "Petal Length",
                        "Petal Width",
                        "Species"))


flex_print(x = head(iris),
           align = c("c"),
           col_nms = names(head(iris)),
           col_lbls = c("Sepal\nLength",
                        "Sepal\nWidth",
                        "Petal Length",
                        "Petal Width",
                        "Species"),
           font_size = 16)

emilelatour/lamisc documentation built on April 9, 2024, 10:33 a.m.