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 |
Add rows to the table with summary statistics.
add_rows(data, row_vars, stat, digits = 1)
add_rows(data, row_vars, stat, digits = 1)
data |
Output from the |
row_vars |
The variables that you want added to the table. Must be from
|
stat |
The summary statistic or any other function. A list of
built functions can be found in |
digits |
What to round the value to. |
Adds a row with summary statistics for a variable. Is a tibble.
carpenter()
for a list of all functions, examples, and
accessing the introduction tutorial vignette. See table_stats()
for a list of carpenter builtin statistics.
Output can be to common formats such as rmarkdown, html, etc, based on the
style
argument of the pander::pander()
function.
build_table(data, caption = NULL, style = "rmarkdown", split = Inf, missing = "", alignment = "center", finish = TRUE)
build_table(data, caption = NULL, style = "rmarkdown", split = Inf, missing = "", alignment = "center", finish = TRUE)
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. |
Creates a pander::pander()
created table.
carpenter()
for a list of all functions, examples, and
accessing the introduction tutorial vignette.
Build common tables for your research needs!
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')
.
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')
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.
outline_table(data, header = NULL)
outline_table(data, header = NULL)
data |
Dataset to use to create the table |
header |
Column or variable(s) that will make up the rows |
Dataframe ready for further carpentry work, like adding rows, summary statistics, renaming, etc.
carpenter()
for a list of all functions, examples, and
accessing the introduction tutorial vignette.
Renaming row and header variables.
renaming(data, type = c("rows", "header"), replace)
renaming(data, type = c("rows", "header"), replace)
data |
The |
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 |
Adds to the table outline to rename the rows and/or header variables in the final table.
carpenter()
for a list of all functions, examples, and
accessing the introduction tutorial vignette.
add_rows()
.Common summary statistics to use in add_rows()
.
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)
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)
x |
Numeric vector to use to calculate the statistic |
digits |
Number of digits to use |
Create a single character string with the summary statistic
carpenter()
for a list of all functions, examples, and
accessing the introduction tutorial vignette.