Package 'carpenter'

Title: Build Common Tables of Summary Statistics for Reports
Description: Mainly used to build tables that are commonly presented for bio-medical/health research, such as basic characteristic tables or descriptive statistics.
Authors: Luke Johnston [aut, cre]
Maintainer: Luke Johnston <[email protected]>
License: MIT + file LICENSE
Version: 0.2.2
Built: 2024-11-01 05:40:34 UTC
Source: https://github.com/lwjohnst86/carpenter

Help Index


Add rows to the table with summary statistics.

Description

Add rows to the table with summary statistics.

Usage

add_rows(data, row_vars, stat, digits = 1)

Arguments

data

Output from the outline_table object.

row_vars

The variables that you want added to the table. Must be from outline_table.

stat

The summary statistic or any other function. A list of built functions can be found in table_stats().

digits

What to round the value to.

Value

Adds a row with summary statistics for a variable. Is a tibble.

See Also

carpenter() for a list of all functions, examples, and accessing the introduction tutorial vignette. See table_stats() for a list of carpenter builtin statistics.


Build the final table.

Description

Output can be to common formats such as rmarkdown, html, etc, based on the style argument of the pander::pander() function.

Usage

build_table(data, caption = NULL, style = "rmarkdown", split = Inf,
  missing = "", alignment = "center", finish = TRUE)

Arguments

data

The draft table object.

caption

Table caption.

style

What output style (rmarkdown, grid, simple, etc) should the table be.

split

When should the table split when it is too wide? (Inf means never).

missing

How to deal with missing values in the table (removed by default).

alignment

Table column alignment.

finish

Generate the final table in markdown formatted form.

Value

Creates a pander::pander() created table.

See Also

carpenter() for a list of all functions, examples, and accessing the introduction tutorial vignette.


Build common tables for your research needs!

Description

Build common tables for your research needs!

See Also

add_rows() to add rows to the table, renaming() for renaming of columns and rows, build_table(), table_stats() for a list of built-in summary statistics. For a more detailed walkthrough of carpenter, see the introduction vignette using vignette('carpenter').

Examples

library(magrittr)
outline_table(iris, 'Species') %>%
 add_rows(c('Sepal.Length', 'Petal.Length'), stat_meanSD) %>%
 add_rows('Sepal.Width', stat_medianIQR) %>%
 renaming('rows', function(x) gsub('Sepal\\.', 'Sepal ', x)) %>%
 renaming('header', c('Measures', 'Setosa', 'Versicolor', 'Virginica')) %>%
 build_table(caption = 'A caption for the table')

Make an outline of the table you want to create.

Description

Make an outline of the table you want to create.

Usage

outline_table(data, header = NULL)

Arguments

data

Dataset to use to create the table

header

Column or variable(s) that will make up the rows

Value

Dataframe ready for further carpentry work, like adding rows, summary statistics, renaming, etc.

See Also

carpenter() for a list of all functions, examples, and accessing the introduction tutorial vignette.


Renaming row and header variables.

Description

Renaming row and header variables.

Usage

renaming(data, type = c("rows", "header"), replace)

Arguments

data

The table_draft object.

type

Whether to rename the row column or the headers.

replace

If type is 'row', needs to be a function (anonymous or otherwise) using the base::gsub() function to substitute patterns, words, characters, or symbols, etc. If type is 'header', needs to be a string of equal length as the header to replace the header variables.

Value

Adds to the table outline to rename the rows and/or header variables in the final table.

See Also

carpenter() for a list of all functions, examples, and accessing the introduction tutorial vignette.


Common summary statistics to use in add_rows().

Description

Common summary statistics to use in add_rows().

Usage

stat_median(x, digits = 1)

stat_iqr(x, digits = 1)

stat_medianIQR(x, digits = 1)

stat_mean(x, digits = 1)

stat_stddev(x, digits = 1)

stat_meanSD(x, digits = 1)

stat_nPct(x, digits = 0)

Arguments

x

Numeric vector to use to calculate the statistic

digits

Number of digits to use

Value

Create a single character string with the summary statistic

See Also

carpenter() for a list of all functions, examples, and accessing the introduction tutorial vignette.