first_table: First Table

View source: R/first-table.R

first_tableR Documentation

First Table

Description

First Table

Usage

first_table(
  .data,
  ...,
  .column_variable = NULL,
  .column_type = c("default", "numeric"),
  .options = first_table_options()
)

Arguments

.data

'data.frame' or 'tibble' to use as data source

...

row details

.column_variable

variable used for columns (if any)

.column_type

type of column (default or numeric)

.options

options to use for formatting (see details)

Details

This function takes a data.frame or tibble and a row and column specification and generates a table along the lines of the first table used in many medical journal articles. The row specification can either use one of the _row functions, or if the defaults are appropriate can just be a bare column name or calculation using a column. These calculations are implemented using eval_tidy and support the quasiquotation operators such as !! and !!!.

Options can be specified as a list or by using first_table_options.

Value

object of class first_table with the requested rows and columns;

Examples

first_table(mtcars,
  .column_variable = cyl,
  "Miles per gallon" = mpg,
  "Transmission" = factor(am))

# Example demonstrating use of quasiquotation from rlang
library(rlang)
my_rows <- quos(
  kruskal_row(Sepal.Length, row_digits = 0),
  "Sepal width" = first_table_row(Sepal.Width, row_digits = 2),
  "Wide petals" = Petal.Width > median(Petal.Width)
)
first_table(iris,
  .column_variable = Species,
  !!!my_rows
)

# Example demonstrating use of survival column variable
library(survival)
first_table(lung,
  .column_variable = Surv(time, status),
  .options = list(include_n = TRUE, include_n_per_col = TRUE),
   ECOG = factor(ph.ecog),
   `Meal calories` = first_table_row(meal.cal, row_digits = 2)
)

NikNakk/firsttable documentation built on April 3, 2022, 7:54 a.m.