pt_cont_long: Continuous data summary in long format

View source: R/continuous_table.R

pt_cont_longR Documentation

Continuous data summary in long format

Description

This function summarizes your data in a specific way and returns an object that can be converted into a latex table.

Usage

pt_cont_long(
  data,
  cols,
  panel = ".total",
  by = NULL,
  table = NULL,
  units = NULL,
  digits = new_digits(),
  summarize_all = TRUE,
  all_name = "All data",
  fun = cont_long_fun,
  na_fill = "--",
  id_col = "ID"
)

Arguments

data

the data frame to summarize; the user should filter or subset so that data contains exactly the records to be summarized; pmtables will not add or remove rows prior to summarizing data

cols

the columns to summarize; may be character vector or quosure

panel

data set column name to stratify the summary

by

a grouping variable that will silently overwrite the value of panel if panel is also passed; see details and the differences in table output when either panel or by are passed

table

a named list to use for renaming columns (see details and examples)

units

a named list to use for unit lookup (see details and examples)

digits

a digits object (see new_digits())

summarize_all

if TRUE then a complete data summary will be appended to the bottom of the table

all_name

a name to use for the complete data summary

fun

the data summary function (see details)

na_fill

value to fill with when all values in the summary are missing

id_col

the ID column name

Details

Passing the panel variable will partition the table in panels defined by the non-repeating values of that data column, and cols will form the rows within each panel. Alternatively, passing in the by variable will panel by the different levels of cols and the levels of by will form the rows within each panel.

The default summary function is cont_long_fun(). Please review that documentation for details on the default summary for this table.

The notes for this table are generated by pt_cont_long_notes().

Value

An object with class pmtable; see class-pmtable.

Custom summary function

The summary function (fun) should take value as the first argument and return a data frame or tibble with one row as many columns as you wish to appear in the table. The function can also accept an id argument which is a vector of IDs that is the same length as value. Be sure to include ... to the function signature as other arguments will be passed along. Make sure your function completely formats the output ... it will appear in the table as you return from this function. See cont_long_fun() for details on the default implementation.

Examples


ans <- pt_cont_long(pmt_first, cols = dplyr::vars(WT,ALB,CRCL))

ans <- pt_cont_long(pmt_first, cols = "WT,CRCL", panel = "SEXf")

ans <- pt_cont_long(pmt_first, cols = "WT,CRCL", by = "SEXf")

pmtables:::cont_long_fun(rnorm(100))


metrumresearchgroup/pmtables documentation built on Dec. 22, 2024, 1:34 a.m.