inst/doc/tables.R

## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  warning = FALSE,
  message = FALSE
)

## ----load---------------------------------------------------------------------
library(Rbearcat)

## ----reg-single---------------------------------------------------------------
m1 <- lm(mpg ~ wt + hp, data = mtcars)
bcat_reg_table(m1, caption = "Model 1: MPG predicted by Weight and Horsepower")

## ----reg-multi----------------------------------------------------------------
m2 <- lm(mpg ~ wt + hp + cyl, data = mtcars)
m3 <- lm(mpg ~ wt + hp + cyl + disp, data = mtcars)

bcat_reg_table(
  list("Base" = m1, "Add Cylinders" = m2, "Full" = m3),
  caption = "Comparing Nested OLS Models"
)

## ----reg-robust---------------------------------------------------------------
bcat_reg_table(m1, se_type = "HC1", caption = "HC1 Robust Standard Errors")

## ----reg-rename---------------------------------------------------------------
bcat_reg_table(
  m2,
  coef_rename = c("wt" = "Weight (1000 lbs)",
                   "hp" = "Horsepower",
                   "cyl" = "Cylinders"),
  gof_map = c("nobs", "r.squared", "adj.r.squared"),
  caption = "Custom Labels"
)

## ----reg-stars----------------------------------------------------------------
bcat_reg_table(
  m1,
  stars = c("+" = 0.1, "*" = 0.05, "**" = 0.01, "***" = 0.001),
  caption = "Alternative Star Convention"
)

## ----sum-basic----------------------------------------------------------------
bcat_sum_table(
  mtcars[, c("mpg", "wt", "hp", "qsec")],
  caption = "Descriptive Statistics for mtcars"
)

## ----sum-grouped--------------------------------------------------------------
bcat_sum_table(
  mtcars[, c("mpg", "wt", "hp", "cyl")],
  by = "cyl",
  caption = "Summary Statistics by Cylinder Count"
)

## ----sum-select---------------------------------------------------------------
bcat_sum_table(
  mtcars[, c("mpg", "hp")],
  stats = c("mean", "sd", "n"),
  caption = "Mean, SD, and N Only"
)

## ----cor-basic----------------------------------------------------------------
bcat_cor_table(
  mtcars[, c("mpg", "wt", "hp", "disp", "qsec")],
  caption = "Pearson Correlation Matrix"
)

## ----cor-spearman-------------------------------------------------------------
bcat_cor_table(
  mtcars[, c("mpg", "wt", "hp")],
  method = "spearman",
  full_matrix = TRUE,
  caption = "Full Spearman Correlation Matrix"
)

## ----cor-nostars--------------------------------------------------------------
bcat_cor_table(
  mtcars[, c("mpg", "wt", "hp")],
  stars = FALSE,
  caption = "Correlation Matrix (No Stars)"
)

## ----style-table--------------------------------------------------------------
bcat_fmt_style_table(
  head(iris, 8),
  caption = "Iris Sample",
  striped = TRUE
)

## ----style-header-------------------------------------------------------------
bcat_fmt_style_table(
  head(iris, 5),
  header = "Iris Dataset — First 5 Rows",
  caption = "With Spanning Header"
)

## ----custom-style-------------------------------------------------------------
bcat_reg_table(
  m1,
  header_bg_color = palette_UC[["Bearcats Black"]],
  font_size = 11,
  footer = "Source: mtcars dataset",
  caption = "Custom Styled Table"
)

Try the Rbearcat package in your browser

Any scripts or data that you put into this service are public.

Rbearcat documentation built on March 21, 2026, 5:07 p.m.