| Title: | Publication-Ready Tables for Biomedical Research |
|---|---|
| Description: | Transforms standard R data frames into publication-ready tables across a handful of common archetypes found in biomedical and neuroscience manuscripts: descriptive/Table 1 with group comparisons, heritability and variance components, correlation and partial correlation, regression coefficients, and simple descriptive summaries. Provides a unified rendering pipeline targeting 'gt' (Word/PDF), 'reactable' (HTML), and LaTeX outputs, with consistent theming, domain/section grouping, footnote handling for transformed variables, and FDR annotation. |
| Authors: | Lucas França [aut, cre] (ORCID: <https://orcid.org/0000-0003-0853-1319>), Mario Leocadio-Miguel [aut] (ORCID: <https://orcid.org/0000-0002-7248-3529>) |
| Maintainer: | Lucas França <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.2 |
| Built: | 2026-07-01 23:56:45 UTC |
| Source: | https://github.com/circadia-bio/clerkR |
Convenience accessor for a single named colour from the clerkR palette.
clerk_colour(name)clerk_colour(name)
name |
Character string. One of the named entries in |
A single hex colour string.
clerk_colour("navy") clerk_colour("header_bg")clerk_colour("navy") clerk_colour("header_bg")
A synthetic dataset of partial correlation results (age + sex controlled)
between eight predictor variables and two cognitive outcomes, designed to
illustrate tbl_correlation(). All values are simulated and bear no
relation to any real study.
clerk_cor_exampleclerk_cor_example
A data frame with 16 rows and 5 variables:
Predictor variable name (character).
Outcome variable name: "tmt_time" or
"verbal_fluency" (character).
Sample size for each correlation (integer).
Partial correlation coefficient (numeric).
Two-tailed p-value (numeric).
Simulated data generated in data-raw/clerk_cor_example.R.
Returns a vector of n hex colours interpolated along the clerkR diverging
scale: dusty terracotta (#D4907E) — neutral off-white (#F0EEEC) — navy
(#293681). Suitable for use with gt::data_color() or
scales::col_numeric().
clerk_diverging(n = 9, reverse = FALSE)clerk_diverging(n = 9, reverse = FALSE)
n |
Integer. Number of colour steps (default |
reverse |
Logical. Reverse the scale direction (default |
A character vector of n hex colour codes.
clerk_diverging() clerk_diverging(n = 5) clerk_diverging(n = 11, reverse = TRUE)clerk_diverging() clerk_diverging(n = 5) clerk_diverging(n = 11, reverse = TRUE)
A synthetic dataset of 300 participants with demographic, metabolic,
anthropometric, cognitive, and mental health variables, designed to
illustrate tbl_descriptive() and other clerkR table constructors.
All values are simulated and bear no relation to any real study.
clerk_exampleclerk_example
A data frame with 300 rows and 12 variables:
Factor: "Female" / "Male".
Age in years (numeric).
HDL cholesterol in mmol/L (numeric).
Fasting glucose in mmol/L (numeric).
Body mass index in kg/m² (numeric).
Waist circumference in cm (numeric).
Systolic blood pressure in mmHg (numeric).
Trail Making Test completion time in seconds, log-scale analysis recommended (numeric).
Verbal fluency score — number of words in 60 s (numeric).
Beck Depression Inventory total score (numeric).
PANAS negative affect subscale score (numeric).
Life Satisfaction Scale total score (numeric).
Simulated data generated in data-raw/clerk_example.R.
A synthetic data frame of narrow-sense heritability (h²) estimates for
three cortical shape metrics across four covariate models, designed to
illustrate tbl_heritability(). Column names match the output of
R-itable::herit_batch() for direct compatibility. All values are
simulated.
clerk_h2_exampleclerk_h2_example
A data frame with 12 rows and 7 variables:
Phenotype name (character).
Covariate model label (character).
Narrow-sense heritability point estimate (numeric).
Lower 95% profile-likelihood CI bound (numeric).
Upper 95% profile-likelihood CI bound (numeric).
One-sided LRT p-value (numeric).
Additive genetic variance component (numeric).
Residual variance component (numeric).
Simulated data generated in data-raw/clerk_h2_example.R.
clerk_options() gets or sets session-level formatting defaults used by all
tbl_* constructors. Defaults are loaded automatically when the package is
attached and follow biomed/APA conventions.
Call with no arguments to inspect current settings. Call with named
arguments to change one or more. Call with reset = TRUE to restore factory
defaults.
clerk_options( digits = NULL, r_digits = NULL, p_digits = NULL, p_threshold = NULL, p_style = NULL, stars = NULL, star_thresholds = NULL, fdr_ns = NULL, fdr_alpha = NULL, fdr_ns_label = NULL, domain_other = NULL, reset = FALSE )clerk_options( digits = NULL, r_digits = NULL, p_digits = NULL, p_threshold = NULL, p_style = NULL, stars = NULL, star_thresholds = NULL, fdr_ns = NULL, fdr_alpha = NULL, fdr_ns_label = NULL, domain_other = NULL, reset = FALSE )
digits |
Integer. Decimal places for continuous summary statistics
(default |
r_digits |
Integer. Decimal places for correlation coefficients and h²
estimates (default |
p_digits |
Integer. Decimal places for p-values (default |
p_threshold |
Numeric. Raw p-values below this are shown as
|
p_style |
Character string controlling p-value display style:
|
stars |
Logical. Append significance stars (default |
star_thresholds |
Numeric vector of length 3. Cutoffs for |
fdr_ns |
Logical. Replace the FDR p-value cell with |
fdr_alpha |
Numeric. Alpha applied to the BH-adjusted p-value.
Cells where |
fdr_ns_label |
Character string for non-surviving FDR cells
(default |
domain_other |
Character string used as the domain label for variables
not assigned to any domain, and for all variables when no domains are
specified. Default |
reset |
Logical. Restore factory defaults (default |
A named list of current option values, returned invisibly.
clerk_options() clerk_options(p_style = "apa", stars = TRUE) clerk_options(fdr_alpha = 0.01) clerk_options(domain_other = "Other") clerk_options(reset = TRUE)clerk_options() clerk_options(p_style = "apa", stars = TRUE) clerk_options(fdr_alpha = 0.01) clerk_options(domain_other = "Other") clerk_options(reset = TRUE)
Returns the named clerkR colour palette as a character vector of hex codes.
Individual colours can be accessed by name via clerk_colour().
The palette pairs a formal cool-blue range (navy → light teal → near-white) with a dusty terracotta warm pole for diverging scales.
clerk_palette()clerk_palette()
A named character vector of hex codes.
clerk_palette() clerk_palette()[["header_bg"]]clerk_palette() clerk_palette()[["header_bg"]]
A synthetic data frame of linear regression results (outcome: log TMT
completion time) designed to illustrate tbl_regression(). Mimics the
output of broom::tidy(lm(...), conf.int = TRUE). All values are simulated.
clerk_reg_exampleclerk_reg_example
A data frame with 7 rows and 6 variables:
Model term / predictor name (character).
Regression coefficient β (numeric).
Standard error of the estimate (numeric).
Lower 95% confidence interval bound (numeric).
Upper 95% confidence interval bound (numeric).
Two-tailed p-value (numeric).
Simulated data generated in data-raw/clerk_reg_example.R.
Dispatches to the correct renderer based on the output slot set at
construction time (tbl_descriptive(..., output = "gt"|"html"|"latex")).
All render arguments (title, subtitle, footnote) can be supplied here
and are forwarded to the underlying renderer.
clerk_render( x, title = NULL, subtitle = NULL, footnote = NULL, fdr_footnote = TRUE, ... )clerk_render( x, title = NULL, subtitle = NULL, footnote = NULL, fdr_footnote = TRUE, ... )
x |
A |
title |
Optional character string for the table title. |
subtitle |
Optional character string for the table subtitle. |
footnote |
Optional additional footnote text. Appended after any automatic footnotes (log-transform, FDR). |
fdr_footnote |
Logical. Automatically add a source note explaining the
FDR correction when a |
... |
Passed to the underlying |
A gt_tbl, htmltools::tagList, or knit_asis object depending
on the output slot of x.
tbl_descriptive(clerk_example, group = sex, output = "gt", fdr = TRUE) |> clerk_render(title = "Table 1") tbl_descriptive(clerk_example, group = sex, output = "html") |> clerk_render(title = "Sample characteristics")tbl_descriptive(clerk_example, group = sex, output = "gt", fdr = TRUE) |> clerk_render(title = "Table 1") tbl_descriptive(clerk_example, group = sex, output = "html") |> clerk_render(title = "Sample characteristics")
Returns a vector of n hex colours interpolated along the clerkR sequential
scale: near-white (#D0E7E6) → navy (#293681). Suitable for shading
columns by magnitude (e.g. heritability h², correlation r).
clerk_sequential(n = 7, reverse = FALSE)clerk_sequential(n = 7, reverse = FALSE)
n |
Integer. Number of colour steps (default |
reverse |
Logical. Reverse the scale direction (default |
A character vector of n hex colour codes.
clerk_sequential() clerk_sequential(n = 5, reverse = TRUE)clerk_sequential() clerk_sequential(n = 5, reverse = TRUE)
Applies the clerkR visual style to an existing gt_tbl object: light teal
column headers with navy text, near-white row group bars, clean borders, and
consistent typography. Can be applied after any gt pipeline.
This function is called automatically by render_gt() and render_latex();
you only need it directly if you are building a gt table outside of the
tbl_* constructors.
clerk_theme(gt_tbl)clerk_theme(gt_tbl)
gt_tbl |
A |
A gt_tbl object with clerkR styling applied.
## Not run: gt::gt(mtcars) |> clerk_theme() ## End(Not run)## Not run: gt::gt(mtcars) |> clerk_theme() ## End(Not run)
Renders a clerk_tbl as a gt table with clerkR styling applied via
clerk_theme(). Domain groupings become row-group labels; log-transformed
variables receive an automatic footnote; FDR-corrected tables receive an
automatic source note. Typically called indirectly via clerk_render().
render_gt( x, title = NULL, subtitle = NULL, footnote = NULL, fdr_footnote = TRUE, ... )render_gt( x, title = NULL, subtitle = NULL, footnote = NULL, fdr_footnote = TRUE, ... )
x |
A |
title |
Optional table title. |
subtitle |
Optional table subtitle. |
footnote |
Optional additional footnote. |
fdr_footnote |
Logical. Add an automatic FDR source note when a
|
... |
Reserved for future use. |
A gt_tbl object.
tbl_descriptive(clerk_example, group = sex) |> render_gt(title = "Table 1")tbl_descriptive(clerk_example, group = sex) |> render_gt(title = "Table 1")
Renders a clerk_tbl as a LaTeX table via gt::as_latex(). Typically
called indirectly via clerk_render().
render_latex( x, title = NULL, subtitle = NULL, footnote = NULL, fdr_footnote = TRUE, ... )render_latex( x, title = NULL, subtitle = NULL, footnote = NULL, fdr_footnote = TRUE, ... )
x |
A |
title |
Optional table title (used as the |
subtitle |
Optional subtitle appended to the caption. |
footnote |
Optional additional footnote. |
fdr_footnote |
Logical. Add an automatic FDR source note (default
|
... |
Reserved for future use. |
A knit_asis character object containing the LaTeX table source.
tbl_descriptive(clerk_example, group = sex, output = "latex") |> clerk_render(title = "Sample characteristics by sex")tbl_descriptive(clerk_example, group = sex, output = "latex") |> clerk_render(title = "Sample characteristics by sex")
Renders a clerk_tbl as a reactable interactive HTML table with optional
title and subtitle rendered above the widget. Typically called indirectly
via clerk_render().
render_reactable(x, title = NULL, subtitle = NULL, footnote = NULL, ...)render_reactable(x, title = NULL, subtitle = NULL, footnote = NULL, ...)
x |
A |
title |
Optional character string displayed as a heading above the table. |
subtitle |
Optional character string displayed as a subheading. |
footnote |
Optional character string displayed as a note below the table. |
... |
Passed to |
An htmltools::tagList containing the title, reactable widget, and
optional footnote, or a bare reactable if no title/subtitle/footnote
are provided.
tbl_correlation(clerk_cor_example, output = "html") |> clerk_render(title = "Partial correlations", subtitle = "age + sex controlled")tbl_correlation(clerk_cor_example, output = "html") |> clerk_render(title = "Partial correlations", subtitle = "age + sex controlled")
Formats a tidy data frame of (partial) correlation results into a
publication-ready table. Column-name arguments accept character strings.
Defaults match a typical correlation results frame with columns named
variable, outcome, r, and p.
Formatting defaults are inherited from clerk_options() and can be
overridden per call.
tbl_correlation( data, predictor = "variable", outcome = "outcome", r = "r", p = "p", n = NULL, extra_cols = NULL, domains = list(), fdr = FALSE, fdr_within = NULL, r_digits = NULL, p_digits = NULL, p_threshold = NULL, p_style = NULL, stars = NULL, fdr_ns = NULL, fdr_alpha = NULL, domain_other = NULL, pivot = FALSE, output = c("gt", "html", "latex") )tbl_correlation( data, predictor = "variable", outcome = "outcome", r = "r", p = "p", n = NULL, extra_cols = NULL, domains = list(), fdr = FALSE, fdr_within = NULL, r_digits = NULL, p_digits = NULL, p_threshold = NULL, p_style = NULL, stars = NULL, fdr_ns = NULL, fdr_alpha = NULL, domain_other = NULL, pivot = FALSE, output = c("gt", "html", "latex") )
data |
A tidy data frame of correlation results. |
predictor |
Character string. Predictor column name. Default
|
outcome |
Character string. Outcome column name. Default |
r |
Character string. Correlation coefficient column. Default |
p |
Character string. P-value column. Default |
n |
Character string or |
extra_cols |
Character vector of additional columns to carry through. |
domains |
A named list mapping predictor names to domain/section labels. |
fdr |
Logical. Apply BH FDR correction (default |
fdr_within |
Character string or |
r_digits |
Integer. Decimal places for r. |
p_digits |
Integer. Decimal places for p-values. |
p_threshold |
Numeric. P-values below this are shown as
|
p_style |
Character. P-value style. |
stars |
Logical. Append significance stars. |
fdr_ns |
Logical. Replace non-surviving FDR p-values with |
fdr_alpha |
Numeric. Alpha level for FDR survival (BH-adjusted p). |
domain_other |
Character string. Label for variables not assigned to
any domain. Default |
pivot |
Logical. Pivot to wide format (default |
output |
Character string. One of |
A clerk_tbl object with type "correlation".
tbl_correlation( clerk_cor_example, domains = list( "Metabolic" = c("hdl", "glucose", "bmi"), "Anthropometric" = c("waist", "systolic_bp"), "Mental health" = c("bdi", "panas_neg") ), fdr = TRUE, output = "gt" ) |> clerk_render(title = "Partial correlations (age + sex controlled)")tbl_correlation( clerk_cor_example, domains = list( "Metabolic" = c("hdl", "glucose", "bmi"), "Anthropometric" = c("waist", "systolic_bp"), "Mental health" = c("bdi", "panas_neg") ), fdr = TRUE, output = "gt" ) |> clerk_render(title = "Partial correlations (age + sex controlled)")
Produces a descriptive/Table 1-style summary of a data frame, with optional
group comparisons. Formatting defaults are inherited from clerk_options().
tbl_descriptive( data, group = NULL, vars = NULL, domains = list(), log_vars = character(0), digits = NULL, p_digits = NULL, p_threshold = NULL, p_style = NULL, stars = NULL, fdr = FALSE, fdr_ns = NULL, fdr_alpha = NULL, domain_other = NULL, overall = TRUE, output = c("gt", "html", "latex") )tbl_descriptive( data, group = NULL, vars = NULL, domains = list(), log_vars = character(0), digits = NULL, p_digits = NULL, p_threshold = NULL, p_style = NULL, stars = NULL, fdr = FALSE, fdr_ns = NULL, fdr_alpha = NULL, domain_other = NULL, overall = TRUE, output = c("gt", "html", "latex") )
data |
A data frame. |
group |
< |
vars |
< |
domains |
A named list mapping variable names to domain/section labels. |
log_vars |
Character vector of log-transformed variable names. |
digits |
Integer. Decimal places for continuous variables. |
p_digits |
Integer. Decimal places for p-values. |
p_threshold |
Numeric. P-values below this are shown as
|
p_style |
Character. P-value style ( |
stars |
Logical. Append significance stars. |
fdr |
Logical. Apply BH FDR correction (default |
fdr_ns |
Logical. Replace non-surviving FDR p-values with |
fdr_alpha |
Numeric. Alpha level for FDR survival (BH-adjusted p). |
domain_other |
Character string. Label for variables not assigned to
any domain. Default |
overall |
Logical. Include an overall column (default |
output |
Character string. One of |
A clerk_tbl object with type "descriptive".
tbl_descriptive( clerk_example, group = sex, domains = list( "Metabolic" = c("hdl", "glucose", "bmi"), "Cognitive" = c("tmt_time", "verbal_fluency"), "Mental health"= c("bdi", "panas_neg") ), log_vars = "tmt_time", output = "gt" ) |> clerk_render(title = "Table 1. Sample characteristics by sex")tbl_descriptive( clerk_example, group = sex, domains = list( "Metabolic" = c("hdl", "glucose", "bmi"), "Cognitive" = c("tmt_time", "verbal_fluency"), "Mental health"= c("bdi", "panas_neg") ), log_vars = "tmt_time", output = "gt" ) |> clerk_render(title = "Table 1. Sample characteristics by sex")
Formats a tidy data frame of narrow-sense heritability estimates (h2) into
a publication-ready table. Column-name defaults match
R-itable::herit_batch() output directly. Formatting defaults inherited
from clerk_options().
tbl_heritability( data, metric = "trait", h2 = "h2", ci_low = "ci_lo", ci_high = "ci_hi", p = "pval", sigma2_a = NULL, sigma2_e = NULL, model = NULL, domains = list(), fdr = FALSE, fdr_within = NULL, r_digits = NULL, p_digits = NULL, p_threshold = NULL, p_style = NULL, stars = NULL, fdr_ns = NULL, fdr_alpha = NULL, domain_other = NULL, output = c("gt", "html", "latex") )tbl_heritability( data, metric = "trait", h2 = "h2", ci_low = "ci_lo", ci_high = "ci_hi", p = "pval", sigma2_a = NULL, sigma2_e = NULL, model = NULL, domains = list(), fdr = FALSE, fdr_within = NULL, r_digits = NULL, p_digits = NULL, p_threshold = NULL, p_style = NULL, stars = NULL, fdr_ns = NULL, fdr_alpha = NULL, domain_other = NULL, output = c("gt", "html", "latex") )
data |
A tidy data frame with one row per trait x covariate model. |
metric |
Character string. Trait column name. Default |
h2 |
Character string. h2 estimate column. Default |
ci_low |
Character string. Lower CI column. Default |
ci_high |
Character string. Upper CI column. Default |
p |
Character string. P-value column. Default |
sigma2_a |
Character string or |
sigma2_e |
Character string or |
model |
Character string or |
domains |
A named list mapping trait names to domain/section labels. |
fdr |
Logical. Apply BH FDR correction (default |
fdr_within |
Character string or |
r_digits |
Integer. Decimal places for h2 and variance components. |
p_digits |
Integer. Decimal places for p-values. |
p_threshold |
Numeric. P-values below this are shown as
|
p_style |
Character. P-value style. |
stars |
Logical. Append significance stars. |
fdr_ns |
Logical. Replace non-surviving FDR p-values with |
fdr_alpha |
Numeric. Alpha level for FDR survival (BH-adjusted p). |
domain_other |
Character string. Label for variables not assigned to
any domain. Default |
output |
Character string. One of |
A clerk_tbl object with type "heritability".
tbl_heritability( clerk_h2_example, model = "covariates", sigma2_a = "sigma2_a", sigma2_e = "sigma2_e", fdr = TRUE, output = "gt" ) |> clerk_render(title = "Heritability estimates")tbl_heritability( clerk_h2_example, model = "covariates", sigma2_a = "sigma2_a", sigma2_e = "sigma2_e", fdr = TRUE, output = "gt" ) |> clerk_render(title = "Heritability estimates")
Formats a tidy data frame of regression results into a publication-ready
table. Accepts broom::tidy() output directly. Formatting defaults
inherited from clerk_options().
tbl_regression( data, term = "term", estimate = "estimate", std_error = "std.error", conf_low = "conf.low", conf_high = "conf.high", p = "p.value", model = NULL, domains = list(), exponentiate = FALSE, fdr = FALSE, fdr_within = NULL, ci_sep = ", ", digits = NULL, p_digits = NULL, p_threshold = NULL, p_style = NULL, stars = NULL, fdr_ns = NULL, fdr_alpha = NULL, domain_other = NULL, output = c("gt", "html", "latex") )tbl_regression( data, term = "term", estimate = "estimate", std_error = "std.error", conf_low = "conf.low", conf_high = "conf.high", p = "p.value", model = NULL, domains = list(), exponentiate = FALSE, fdr = FALSE, fdr_within = NULL, ci_sep = ", ", digits = NULL, p_digits = NULL, p_threshold = NULL, p_style = NULL, stars = NULL, fdr_ns = NULL, fdr_alpha = NULL, domain_other = NULL, output = c("gt", "html", "latex") )
data |
A tidy data frame of regression results. |
term |
Character string. Model term column. Default |
estimate |
Character string. Coefficient column. Default |
std_error |
Character string. SE column. Default |
conf_low |
Character string. Lower CI column. Default |
conf_high |
Character string. Upper CI column. Default |
p |
Character string. P-value column. Default |
model |
Character string or |
domains |
A named list mapping term names to domain/section labels. |
exponentiate |
Logical. Exponentiate estimates and CIs (default
|
fdr |
Logical. Apply BH FDR correction (default |
fdr_within |
Character string or |
ci_sep |
Character string separating CI bounds (default |
digits |
Integer. Decimal places for estimates. |
p_digits |
Integer. Decimal places for p-values. |
p_threshold |
Numeric. P-values below this are shown as
|
p_style |
Character. P-value style. |
stars |
Logical. Append significance stars. |
fdr_ns |
Logical. Replace non-surviving FDR p-values with |
fdr_alpha |
Numeric. Alpha level for FDR survival (BH-adjusted p). |
domain_other |
Character string. Label for variables not assigned to
any domain. Default |
output |
Character string. One of |
A clerk_tbl object with type "regression".
tbl_regression( clerk_reg_example, domains = list( "Cardiometabolic" = c("bmi", "waist", "systolic_bp"), "Mental health" = c("bdi", "panas_neg") ), fdr = TRUE, output = "gt" ) |> clerk_render(title = "Linear regression: TMT completion time")tbl_regression( clerk_reg_example, domains = list( "Cardiometabolic" = c("bmi", "waist", "systolic_bp"), "Mental health" = c("bdi", "panas_neg") ), fdr = TRUE, output = "gt" ) |> clerk_render(title = "Linear regression: TMT completion time")
Produces a concise descriptive summary — mean ± SD for continuous variables
and n (%) for categorical variables — with no group comparisons or
statistical tests. Formatting defaults inherited from clerk_options().
tbl_simple( data, vars = NULL, domains = list(), log_vars = character(0), digits = NULL, domain_other = NULL, output = c("gt", "html", "latex") )tbl_simple( data, vars = NULL, domains = list(), log_vars = character(0), digits = NULL, domain_other = NULL, output = c("gt", "html", "latex") )
data |
A data frame. |
vars |
< |
domains |
A named list mapping variable names to domain/section labels. |
log_vars |
Character vector of log-transformed variable names. |
digits |
Integer. Decimal places for continuous variables. |
domain_other |
Character string. Label for variables not assigned to
any domain. Default |
output |
Character string. One of |
A clerk_tbl object with type "simple".
tbl_simple( clerk_example, domains = list( "Metabolic" = c("hdl", "glucose", "bmi"), "Mental health"= c("bdi", "panas_neg") ), log_vars = "tmt_time", output = "gt" ) |> clerk_render(title = "Descriptive statistics")tbl_simple( clerk_example, domains = list( "Metabolic" = c("hdl", "glucose", "bmi"), "Mental health"= c("bdi", "panas_neg") ), log_vars = "tmt_time", output = "gt" ) |> clerk_render(title = "Descriptive statistics")