Package {easytable}


Type: Package
Title: Create Multi-Format Regression Tables
Version: 2.1.1
Description: Create publication-ready regression tables in multiple formats, including 'Word', 'HTML', 'LaTeX', and 'PDF', from statistical models. Supports lm() and glm() models. Includes options for marginal effects, control variable grouping, and robust standard errors using methods described in Zeileis (2004) <doi:10.18637/jss.v011.i10>. Tables can be exported to 'Word' via 'flextable' or to 'LaTeX' for 'PDF' output.
License: MIT + file LICENSE
Encoding: UTF-8
RoxygenNote: 7.3.3
Imports: dplyr, flextable, magrittr, stats
Suggests: knitr, kableExtra, lmtest, sandwich, margins, rmarkdown, testthat (≥ 3.0.0), palmerpenguins
VignetteBuilder: knitr
URL: https://github.com/alfredo-hs/easytable
BugReports: https://github.com/alfredo-hs/easytable/issues
NeedsCompilation: no
Packaged: 2026-05-06 20:36:28 UTC; alhdzsz
Author: Alfredo Hernandez Sanchez [aut, cre]
Maintainer: Alfredo Hernandez Sanchez <alhdzsz@gmail.com>
Repository: CRAN
Date/Publication: 2026-05-12 19:00:07 UTC

easytable: Create Multi-Format Regression Tables

Description

logo

Create publication-ready regression tables in multiple formats, including 'Word', 'HTML', 'LaTeX', and 'PDF', from statistical models. Supports lm() and glm() models. Includes options for marginal effects, control variable grouping, and robust standard errors using methods described in Zeileis (2004) doi:10.18637/jss.v011.i10. Tables can be exported to 'Word' via 'flextable' or to 'LaTeX' for 'PDF' output.

Author(s)

Maintainer: Alfredo Hernandez Sanchez alhdzsz@gmail.com

See Also

Useful links:


Pipe Operator

Description

Re-export of ⁠%>%⁠ from 'magrittr'.

Usage

lhs %>% rhs

Value

The result of evaluating the right-hand side expression after the left-hand side has been passed through the pipe.


Abbreviate variable name

Description

Deterministic abbreviation rules:

Usage

abbreviate_var_name(var_name, is_intercept = FALSE)

Arguments

var_name

Character string

is_intercept

Logical indicating if this variable is the intercept

Value

Character string


Check format-specific dependencies

Description

Check format-specific dependencies

Usage

check_format_dependencies(output)

Arguments

output

Output format ("word" or "latex")

Value

Invisible TRUE if dependencies available, otherwise stops with error


Check margins dependencies

Description

Check margins dependencies

Usage

check_margins_dependencies(margins)

Arguments

margins

Logical indicating if marginal effects are requested

Value

Invisible TRUE if dependencies available, otherwise stops with error


Check robust SE dependencies

Description

Check robust SE dependencies

Usage

check_robust_dependencies(robust.se)

Arguments

robust.se

Logical indicating if robust SEs are requested

Value

Invisible TRUE if dependencies available, otherwise stops with error


Collapse control variable rows

Description

Collapses multiple rows for control variables (including factor levels and transformations) into a single row per control variable.

Usage

collapse_control_vars(table, control.var, levels_map = NULL)

Arguments

table

A data frame with regression results

control.var

Character vector of control variable names to collapse

Value

A data frame with collapsed control variables


Remove duplicate control variable rows

Description

After collapsing control variables, removes duplicate rows but keeps one representative row per control variable for each model.

Usage

deduplicate_control_vars(table)

Arguments

table

A data frame with regression results

Value

A data frame with duplicates removed


Create Multi-Format Regression Tables

Description

Takes model objects as arguments and creates formatted tables for Word or LaTeX/PDF output. Supports robust standard errors, marginal effects, and control variable grouping.

Usage

easytable(
  ...,
  model.names = NULL,
  output = "word",
  export.word = NULL,
  export.csv = NULL,
  robust.se = FALSE,
  control.var = NULL,
  margins = FALSE,
  highlight = FALSE,
  abbreviate = FALSE,
  table_size = "normalsize",
  digits = 2,
  custom.row = NULL
)

Arguments

...

Statistical model objects (lm or glm). Pass models directly like easytable(m1, m2, m3).

model.names

Character vector of custom names for model columns. If NULL (default), columns are named "Model 1", "Model 2", etc. Length must match number of models.

output

Character string specifying output format. One of:

  • "word" - Microsoft Word via flextable (default)

  • "latex" - LaTeX for PDF output

export.word

Character string ending in .docx for Word file export. Only supported when output = "word". If NULL (default), no file is written.

export.csv

Character string ending in .csv for CSV export. If NULL (default), no CSV file is written.

robust.se

Logical. Use robust standard errors (HC type)? Default FALSE. Requires packages: lmtest, sandwich

control.var

Character vector of variable names to group as "control variables". These will be collapsed into single rows showing "Y" for presence instead of individual coefficients. Default NULL.

margins

Logical. Compute average marginal effects (AME)? Default FALSE. Requires package: margins

highlight

Logical. Highlight significant coefficients (positive in green, negative in red)? Default FALSE. Works best with Word output.

abbreviate

Logical. Abbreviate variable names for readability? Default FALSE. When TRUE, long variable names are shortened using deterministic rules.

table_size

Character string specifying LaTeX table size. Only works with output = "latex". Options: "tiny", "small", "normalsize", "scriptsize". Default "normalsize". Error if used with Word output.

digits

Number of digits after the decimal point for coefficients and standard errors, including the mantissa in scientific notation. Allowed values are 0 to 4. Default 2.

custom.row

Optional character vector for an additional row placed at the bottom of the statistics block. The first element is the row label and each subsequent element is the value for the corresponding model column. The vector must have exactly one more element than the number of models. Default NULL (no extra row).

Details

The function extracts coefficients, standard errors, and p-values from each model, adds significance stars (*** p<.01, ** p<.05, * p<.1), and includes model fit statistics such as N, R-squared, Adjusted R-squared, and AIC (for glm models).

Control variables can be grouped to show presence/absence rather than individual coefficients for each factor level or transformation.

Term labels are automatically formatted for readability:

Value

Depends on output:

Dependencies


Extract goodness-of-fit measures from a model

Description

Rounding is fixed per statistic and independent of the user-facing digits option: N = 0, R sq. = 2, Adj. R sq. = 2, AIC = 0. AIC is only reported for glm models.

Usage

extract_model_measures(model)

Arguments

model

A statistical model object (lm or glm)

Value

A data frame with model fit statistics


Format coefficients with significance stars and standard errors

Description

Format coefficients with significance stars and standard errors

Usage

format_coefficients(coef_data, digits = 2)

Arguments

coef_data

A data frame with columns: term, estimate, std.error, p.value

digits

Integer number of digits after the decimal point for coefficients and standard errors, including the mantissa in scientific notation. Allowed values are 0 to 4. Default 2. Does not affect p-value star thresholds.

Value

A data frame with formatted coefficient strings


Format table for LaTeX/PDF output

Description

Creates a LaTeX table suitable for PDF documents. Uses booktabs styling and includes significance footnotes via threeparttable package.

Usage

format_latex(
  table,
  robust.se = FALSE,
  margins = FALSE,
  highlight = FALSE,
  table_size = "normalsize"
)

Arguments

table

A transformed data frame from transform_table()

robust.se

Logical indicating if robust standard errors were used

margins

Logical indicating if marginal effects were computed

highlight

Logical indicating whether to highlight significant results

table_size

LaTeX size command: "tiny", "small", "normalsize", "scriptsize"

Value

A character string containing the LaTeX table code


Format term labels for display

Description

Transformations:

Usage

format_term_labels(
  terms,
  row_types = NULL,
  levels_map = NULL,
  abbreviate = FALSE
)

Arguments

terms

Character vector of displayed term labels.

row_types

Optional character vector of row types

levels_map

List mapping factor names to their levels

abbreviate

Logical. Apply abbreviation? Default FALSE


Format table for Word output

Description

Creates a flextable object formatted for Microsoft Word documents. Includes significance footnotes, optional highlighting, and notes about robust standard errors or marginal effects.

Usage

format_word(table, robust.se = FALSE, margins = FALSE, highlight = FALSE)

Arguments

table

A transformed data frame from transform_table()

robust.se

Logical indicating if robust standard errors were used

margins

Logical indicating if marginal effects were computed

highlight

Logical indicating whether to highlight significant results

Value

A flextable object ready for export to Word


Get first model statistic row index

Description

Get first model statistic row index

Usage

get_first_measure_row(table)

Get measure row names

Description

Get measure row names

Usage

get_measure_names()

Get indices of model statistic rows

Description

Get indices of model statistic rows

Usage

get_measure_row_indices(table)

Check if a package is available

Description

Check if a package is available

Usage

is_package_available(pkg)

Check if model is supported type

Description

Check if model is supported type

Usage

is_supported_model(model)

Arguments

model

A statistical model object

Value

Logical indicating if model type is supported


Ensure labels are unique via numeric suffix

Description

Ensure labels are unique via numeric suffix

Usage

make_unique_labels(labels)

Mark control variables with 'Y' indicator

Description

Replaces coefficient values with "Y" for control variables to indicate their presence in the model without showing individual coefficients.

Usage

mark_control_vars(table, control.var)

Arguments

table

A data frame with regression results

control.var

Character vector of control variable names

Value

A data frame with control variables marked as "Y"


Parse a model and return formatted results

Description

Main parsing function that combines coefficient extraction, formatting, and measure calculation.

Usage

parse_model(model, robust.se = FALSE, margins = FALSE, digits = 2)

Arguments

model

A statistical model object (lm or glm)

robust.se

Logical indicating whether to use robust standard errors

margins

Logical indicating whether to compute marginal effects

digits

Integer number of digits after the decimal point for coefficients and standard errors, including the mantissa in scientific notation. Allowed values are 0 to 4.

Value

A data frame with one column for terms and one for formatted estimates


Parse multiple models into a combined table

Description

Parse multiple models into a combined table

Usage

parse_models(model_list, robust.se = FALSE, margins = FALSE, digits = 2)

Arguments

model_list

A named list of statistical models

robust.se

Logical indicating whether to use robust standard errors

margins

Logical indicating whether to compute marginal effects

digits

Integer number of digits after the decimal point for coefficients and standard errors, including the mantissa in scientific notation. Allowed values are 0 to 4.

Value

A data frame with terms in rows and models in columns


Parse a single statistical model

Description

Extracts coefficients, standard errors, and p-values from a statistical model. Supports options for robust standard errors and marginal effects.

Usage

parse_single_model(model, robust.se = FALSE, margins = FALSE)

Arguments

model

A statistical model object (lm or glm)

robust.se

Logical indicating whether to use robust standard errors

margins

Logical indicating whether to compute marginal effects

Value

A data frame with columns: term, estimate, std.error, p.value


Separate model statistics from coefficients

Description

Splits the table into coefficient rows and model-stat rows (control indicators, N, R sq., etc.), removes empty stat rows, then recombines with stats at the bottom.

Usage

separate_measures(table, control.var = NULL)

Arguments

table

A data frame with regression results

control.var

Character vector of control variable names

Value

A data frame with measures at the bottom


Sort table with control variables last

Description

Sorts the table so that control variables (marked with "Y") appear after regular variables, ordered by how many models they appear in.

Usage

sort_table(table)

Arguments

table

A data frame with regression results

Value

A sorted data frame


Detect and split factor level suffix using model metadata

Description

Detect and split factor level suffix using model metadata

Usage

split_factor_level(term, levels_map = NULL)

Extract tidy coefficients from a coeftest matrix

Description

Extract tidy coefficients from a coeftest matrix

Usage

tidy_coeftest(x)

Arguments

x

A coeftest object from lmtest::coeftest()

Value

A data frame with columns: term, estimate, std.error, p.value


Extract tidy marginal effects from a margins object

Description

Extract tidy marginal effects from a margins object

Usage

tidy_margins(model)

Arguments

model

A statistical model object (lm or glm)

Value

A data frame with columns: term, estimate, std.error, p.value


Extract tidy coefficients from a model using base R

Description

Includes aliased (perfectly collinear) terms as NA rows, matching the behaviour of broom::tidy().

Usage

tidy_model(model)

Arguments

model

A statistical model object (lm or glm)

Value

A data frame with columns: term, estimate, std.error, p.value


Transform parsed model table

Description

Main transformation function that handles control variables, sorting, deduplication, organization, and term label formatting.

Usage

transform_table(parsed_table, control.var = NULL, abbreviate = FALSE)

Arguments

parsed_table

A data frame from parse_models()

control.var

Character vector of control variable names

abbreviate

Logical. Abbreviate variable names? Default FALSE

Value

A transformed data frame ready for formatting


Validate control variables exist in models

Description

Validate control variables exist in models

Usage

validate_control_vars(model_list, control.var)

Arguments

model_list

A named list of models

control.var

Character vector of control variable names

Value

Invisible TRUE if valid, otherwise stops with error


Validate custom.row parameter

Description

Validate custom.row parameter

Usage

validate_custom_row(custom.row, n_models)

Arguments

custom.row

Character vector or NULL

n_models

Integer number of models in the table

Value

Invisible TRUE if valid, otherwise stops with error


Validate digits parameter

Description

Validate digits parameter

Usage

validate_digits(digits)

Arguments

digits

Integer number of digits after the decimal point. Allowed values are 0 to 4.

Value

Invisible TRUE if valid, otherwise stops with error


Validate model list input

Description

Validate model list input

Usage

validate_model_list(model_list)

Arguments

model_list

A named list of models

Value

Invisible TRUE if valid, otherwise stops with error


Validate all models in list are supported types

Description

Validate all models in list are supported types

Usage

validate_model_types(model_list)

Arguments

model_list

A named list of models

Value

Invisible TRUE if valid, otherwise stops with error


Validate output format

Description

Validate output format

Usage

validate_output_format(output)

Arguments

output

Character string specifying output format

Value

A normalized output string


Validate parameter types

Description

Validate parameter types

Usage

validate_parameters(
  robust.se,
  margins,
  highlight,
  export.word,
  export.csv,
  output
)

Arguments

robust.se

Logical for robust standard errors

margins

Logical for marginal effects

highlight

Logical for highlighting

export.word

Character or NULL for Word export path

export.csv

Character or NULL for CSV export path

output

Character string specifying output format

Value

Invisible TRUE if valid, otherwise stops with error


Validate table_size parameter

Description

Validate table_size parameter

Usage

validate_table_size(table_size, output)

Arguments

table_size

Character string specifying LaTeX table size

output

Character string specifying output format

Value

Invisible TRUE if valid, otherwise stops with error


Wrap interaction terms to reduce term-column width

Description

For Word output, "x1 * x2" becomes "x1\\n× x2".

Usage

wrap_interaction_terms(terms, output = c("word", "latex"))

Arguments

terms

Character vector of displayed term labels.

output

Output backend used for display formatting. "word" uses a literal multiplication sign, while "latex" uses a LaTeX-safe multiplication symbol.

Value

Character vector with interaction terms wrapped for display.