Package {wjake}


Title: Personal Themes and Formatting Preferences
Version: 1.0.0
Description: A collection of utility functions, themes, and templates to support personal data analysis workflows. Includes functions for formatting numeric values as text, custom themes and color scales for 'ggplot2', and automatic formatting for tables created with 'gt'.
License: MIT + file LICENSE
URL: https://github.com/wjakethompson/wjake, https://wjake.wjakethompson.com
BugReports: https://github.com/wjakethompson/wjake/issues
Depends: R (≥ 4.5.0)
Imports: cli, colorspace, dplyr, english, ggplot2 (≥ 4.0.0), ggtext, gh, glue, grDevices, gt, knitr, pak, rlang (≥ 1.1.0), rstudioapi, scales, showtextdb, stringr, sysfonts, systemfonts, xfun
Suggests: spelling, taylor, testthat, vdiffr, withr
Config/testthat/edition: 3
Config/Needs/website: wjakethompson/wjaketemplate
Config/Needs/check: wjakethompson/wjaketemplate
Config/Needs/coverage: wjakethompson/wjaketemplate
Encoding: UTF-8
Language: en-US
RoxygenNote: 7.3.3
NeedsCompilation: no
Packaged: 2026-05-15 16:21:36 UTC; jakethompson
Author: W. Jake Thompson ORCID iD [aut, cre, cph]
Maintainer: W. Jake Thompson <wjakethompson@gmail.com>
Repository: CRAN
Date/Publication: 2026-05-20 08:00:02 UTC

wjake: A package for package installation and miscellaneous functions

Description

Personal package for helping with R setup and random tasks that I Google too often.

Author(s)

Maintainer: W. Jake Thompson wjakethompson@gmail.com (ORCID) [copyright holder]

See Also

Useful links:


Create an announcement adjective

Description

Create an announcement adjective

Usage

announce()

Value

A character string

Examples

announce()

Write APA Words

Description

Confused about whether a number should be written out ("five") or use numerals ("5")? Use this function! Most useful for R Markdown in-text writing.

Usage

apa_words(x, ordinal = FALSE, negative = "negative")

Arguments

x

The number to be printed

ordinal

Do you want the ordinal numbering (e.g., 1st, 6th, etc.)

negative

The word used to indicate a negative number.

Value

A character string

See Also

Other formatters: formatting

Examples

apa_words(5)
apa_words(16)
apa_words(6, ordinal = TRUE)

Create heading dividers

Description

Insert some hyphens padded to a specified console character width.

Usage

code_heading(width = 80)

Arguments

width

The width of console the hyphens should pad to

Value

A character string consisting of a ' ' and hyphens that fill to the specified width.

Examples


code_heading()


Custom color ramps

Description

These color ramp functions create color scales that can be used for making ggplot2 plots and gt tables. Color ramps are based on the palette_wjake color palette.

Usage

make_color_pal(colors, bias = 1)

ramp_blue(output, end = "#FFFFFF")

ramp_yellow(output, end = "#FFFFFF")

ramp_yelblu(output, mid = "#F0F0F0")

ramp_orgblu(output, mid = "#999999")

Arguments

colors

colors to interpolate; must be a valid argument to col2rgb().

bias

a positive number. Higher values give more widely spaced colors at the high end.

output

Colors to pull from the color ramp. Numbers range from 0-1, which is a normalized sliding scale of the color ramp.

end

The end color that the base color should fade into.

mid

For pre-made diverging palettes, the color of the midpoint of the scale.

Details

make_color_pal() can be used to create a color ramp function for any set of valid colors.

ramp_blue(), ramp_yellow(), and ramp_yelblu() are pre-made color ramps based on the blue and yellow colors from the palette_wjake color palette.

ramp_orgblu() is a pre-made color ramp based on the first two colors from the palette_okabeito color palette.

Value

make_color_pal() returns a function that accepts a numeric vector of values between 0 and 1 and returns a character vector of hex color codes. ramp_blue(), ramp_yellow(), ramp_yelblu(), and ramp_orgblu() return a character vector of hex color codes.

Examples

new_ramp <- make_color_pal(c("red", "grey", "blue"))
new_ramp(seq(0, 1, length.out = 10))

# Pre-made palettes
ramp_blue(seq(0, 1, by = 0.2))
ramp_yellow(seq(0.2, 1, length.out = 5))

Text and Number Formatting

Description

These formatting functions are used to format numerical values in a consistent manner. This is useful for printing numbers inline with text, as well as for formatting tables.

Usage

fmt_digits(
  x,
  digits = 1,
  big_mark = ",",
  min_value = -Inf,
  max_value = Inf,
  sub_threshold = 1/(10^digits),
  keep_boundary = FALSE,
  ...
)

fmt_count(x, ...)

fmt_corr(x, digits = 3, ...)

fmt_prop(x, digits = 2, ...)

fmt_pct(x, digits = 0, ...)

fmt_prop_pct(x, digits = 0, ...)

Arguments

x

Number to be formatted.

digits

Number of decimal places to retain.

big_mark

Character used between every 3 digits to separate thousands.

min_value

The minimum value x can take.

max_value

The maximum value x can take.

sub_threshold

The threshold to use when replacing value extremely close to min_value or max_value. By default, this is determined by the digits specified.

keep_boundary

Whether to preserve true values of boundaries (i.e., min_value and max_value). For example if digits = 3, min_value = 0, and keep_boundary = FALSE, a value exactly equal to 0 will become "<.001". If keep_boundary = TRUE, then a value of 0 will remain "0.000", and other small values (e.g., 0.000001) will continue to be replaced with "<.001".

...

Additional arguments passed to scales::number_format() or fmt_digits(). See Details for additional information.

Details

fmt_digits() is a wrapper for scales::number_format() and prints a number with the specified number of digits, suppressing values close to the minimum and maximum values as necessary.

Several helper functions are provided that wrap fmt_digits() with common patterns of min_value, max_value, and digits.

Value

The updated character object of the same length as x.

References

American Psychological Association. (2020). Publication manual of the American Psychological Association (7th ed.). doi:10.1037/0000165-000

See Also

Other formatters: apa_words()

Examples

fmt_digits(runif(5, min = 5, max = 15), digits = 1)
fmt_digits(runif(5, min = 5, max = 15), digits = 3)

fmt_count(sample(10000:99999, size = 5))

fmt_corr(runif(5, min = -1, max = 1))

fmt_prop(runif(5, min = 0, max = 1))

fmt_pct(runif(5, min = 0, max = 100))

fmt_prop_pct(runif(5, min = 0, max = 1))


Title

Description

Title

Usage

gt_theme_apa(
  data,
  dec_dig = 1,
  corr_dig = 3,
  fmt_extreme = TRUE,
  bg_color = "#FFFFFF",
  font = "Arial",
  font_size = 11,
  ...
)

Arguments

data

The gt table data object.

dec_dig

The number of decimal places to round to for numeric values.

corr_dig

The number of decimal places to round to for numeric values all constrained to be between [-1, 1].

fmt_extreme

Logical indicator for whether values close to extremes should be suppressed (e.g., .000001 becomes <.001).

bg_color

The background color of the table.

font

The font to use for the table.

font_size

The base font size for the table.

...

Additional options passed to gt::tab_options()

Value

An object of class gt-tbl.

Examples

gt::gt(head(penguins)) |>
  gt_theme_apa() |>
  gt::fmt_number(year, sep_mark = "", decimals = 0)

Personalized gt theme

Description

A custom theme for tables generated with gt::gt().

Usage

gt_theme_wjake(data, bg_color = "#F0F0F0", font_size = 16, ...)

Arguments

data

The gt table data object.

bg_color

The background color of the table.

font_size

The base font size for the table.

...

Additional arguments passed to gt_theme_apa() and gt::tab_options().

Value

An object of class gt_tbl.

Examples

gt::gt(head(penguins)) |>
  gt_theme_wjake()

Okabe-Ito color palette

Description

Colorblind friendly palette taken originally described by Okabe and Ito (2008). The original palette has been modified slightly to make the yellow more visible on a white background, as described by Lüdecke et al. (2021). The palette also includes color scales that can be used in place of ggplot2::scale_color_discrete() or ggplot2::scale_fill_discrete().

Usage

palette_okabeito

Format

A character vector of 8 hex color codes.

References

Lüdecke, D., Patil, I., Ben-Shachar, M. S., Wiernik, B. M., Waggoner, P., & Makowski, D. (2021). see: An R package for visualizing statistical models. Journal of Open Source Software, 6(64), Article 3393. doi:10.21105/joss.03393

Okabe, M., & Ito, K. (2008). Color universal design (CUD): How to make figures and presentations that are friendly to colorblind people. https://jfly.uni-koeln.de/color/#pallet (Original work published 2002)

Examples

scales::show_col(palette_okabeito)

Personal color palette

Description

Color palette used for theming https://wjakethompson.com. The palette also includes color scales that can be used in place of ggplot2::scale_color_discrete() or ggplot2::scale_fill_discrete().

Usage

palette_wjake

Format

A character vector of 5 hex color codes.

Examples

scales::show_col(palette_wjake)

Round to a specified value

Description

Round to a specified value

Usage

round_to(x, accuracy, direction = c("nearest", "up", "down", "random"))

Arguments

x

A numeric value to round.

accuracy

The accuracy with which to round (i.e., round to the nearest accuracy).

direction

The direction to round. nearest (default) will round to the nearest accuracy, up will round up to the nearest accuracy, down will round down to the nearest accuracy, and random will randomly round up or down to the nearest accuracy as described by Matthews & Harel (2011).

Value

A numeric rounded to the specified accuracy.

References

Matthews, G., & Harel, O. (2011). Data confidentiality: A review of methods for statistical disclosure limitation and methods for assessing privacy. Statistics Surveys, 5, 1–29. doi:10.1214/11-SS074

Examples

round_to(15, accuracy = 7, direction = "nearest")
round_to(15, accuracy = 7, direction = "up")
round_to(20, accuracy = 7, direction = "down")

Palette color scale

Description

This is a qualitative scale using the color palette used for https://wjakethompson.com. See palette_wjake for details.

Arguments

palette

A character vector of the color palette to use in the scale (e.g., palette_wjake, palette_okabeito).

order

Numeric vector listing the order in which the colors should be used. Default is the order of the palette vector.

darken

Relative amount by which the scale should be darkened (for positive values) or lightened (for negative values).

alpha

Alpha transparency level of the color. Default is no transparency.

...

common discrete scale parameters: name, breaks, labels, na.value, limits, guide, and aesthetics. See ggplot2::discrete_scale for more details.

Value

A ScaleDiscrete object that can be added to a ggplot2::ggplot().

Examples

library(ggplot2)

ggplot(penguins, aes(x = bill_len, y = flipper_len, color = species)) +
  geom_point() +
  scale_color_wjake()

ggplot(penguins, aes(bill_len, fill = species)) +
  geom_density(alpha = 0.7) +
  scale_fill_okabeito(order = c(1, 2, 5))


Personalized ggplot2 theme

Description

Based on ggplot2::theme_minimal().

Usage

theme_wjake(
  base_size = 11.5,
  base_family = "Source Sans Pro",
  header_family = NULL,
  base_line_size = base_size/22,
  base_rect_size = base_size/22,
  ink = "black",
  paper = "white",
  accent = "#FED766",
  continuous = ramp_blue(c(0.1, 1), end = "#FFFFFF"),
  discrete = palette_wjake,
  transparent = FALSE,
  ...
)

Arguments

base_size

base font size, given in pts.

base_family

base font family

header_family

font family for titles and headers. The default, NULL, uses theme inheritance to set the font. This setting affects axis titles, legend titles, the plot title and tag text.

base_line_size

base size for line elements

base_rect_size

base size for rect elements

ink, paper, accent

colour for foreground, background, and accented elements respectively.

continuous

A character vector of valid colors that will be interpolated into a continuous color scale.

discrete

A character vector of colors to use for discrete color scales.

transparent

Logical indicator for whether the background of the plot should be transparent.

...

Additional parameters passed to ggplot2::theme().

Value

A theme object that can be added to a ggplot2::ggplot().

Examples

library(ggplot2)

ggplot(penguins, aes(x = bill_len, y = flipper_len)) +
  geom_point(aes(color = species), na.rm = TRUE) +
  labs(
    x = "Bill length (mm)",
    y = "Flipper length (mm)",
    title = "Seminal ggplot2 scatterplot example",
    subtitle = "A plot that is only useful for demonstration purposes",
    caption = "Brought to you by the letter *p*",
    color = "Species"
  ) +
  theme_wjake(base_family = "sans")

Write a bibliography for R packages

Description

Write a bibliography for R packages

Usage

write_pkg_bib(pkg, file, update = FALSE)

Arguments

pkg

A vector of packages to create a .bib file for.

file

The file to save the references.

update

Should packages be updated before creating the bibliography?

Value

A list containing the citations. Citations are also written to the file as a side effect.

Examples

write_pkg_bib(c("ggplot2", "gt"), file = tempfile(fileext = "bib"))

X & Y scales for percent and comma labels

Description

Wrappers around ggplot2::continuous_scale() that provide automatic percent or comma formatting.

Usage

scale_x_comma(...)

scale_y_comma(...)

scale_x_percent(...)

scale_y_percent(...)

Arguments

...

Additional arguments passed to ggplot2::scale_x_continuous() or ggplot2::scale_y_continuous().

Value

A ggplot2 continuous scale.

Examples

library(ggplot2)
set.seed(1234)

ggplot() +
  geom_point(aes(x = sample(1000:9999, size = 100), y = runif(100, 0, 1))) +
  scale_x_comma() +
  scale_y_percent(breaks = seq(0, 1, by = .2))