2
1
Fork
You've already forked AddFonts
0
No description
  • R 100%
gnoblet e781ad02db
All checks were successful
pkgdown / pkgdown (push) Successful in 21s
R-CMD-check / R-CMD-check (push) Successful in 3m56s
test-coverage / test-coverage (push) Successful in 3m41s
docs: initial site build
2026年07月08日 11:17:34 +02:00
.forgejo/workflows ci: build pkgdown locally via pre-commit, deploy-only in CI 2026年07月08日 11:14:34 +02:00
.github feat: add test coverage workflow for Codeberg 2026年07月02日 13:14:15 +02:00
data-raw Initial commit – fresh start 2026年02月12日 13:30:26 +01:00
docs docs: initial site build 2026年07月08日 11:17:34 +02:00
inst/extdata feat: add FontProviderFile, first-use messages, and BBB provider 2026年04月16日 03:14:09 +02:00
man doc: add failed_keys missing param 2026年07月02日 11:40:16 +02:00
pkgdown/favicon docs: initial site build 2026年07月08日 11:17:34 +02:00
R fix: resolve R CMD check warning and notes for CRAN 2026年07月08日 00:26:09 +02:00
rv Initial commit – fresh start 2026年02月12日 13:30:26 +01:00
tests tests: expand coverage for as_list, cache paths, and FontProviderFile ( fix #6 ) 2026年07月02日 12:18:31 +02:00
.gitignore chore: fix .gitignore formatting 2026年07月06日 20:48:35 +02:00
.pre-commit-config.yaml ci: build pkgdown locally via pre-commit, deploy-only in CI 2026年07月08日 11:14:34 +02:00
.Rbuildignore ci: build pkgdown locally via pre-commit, deploy-only in CI 2026年07月08日 11:14:34 +02:00
.Rprofile Initial commit – fresh start 2026年02月12日 13:30:26 +01:00
_pkgdown.yml Initial commit – fresh start 2026年02月12日 13:30:26 +01:00
AddFonts.Rproj Initial commit – fresh start 2026年02月12日 13:30:26 +01:00
cran-comments.md Initial commit – fresh start 2026年02月12日 13:30:26 +01:00
DESCRIPTION fix: resolve R CMD check warning and notes for CRAN 2026年07月08日 00:26:09 +02:00
hex-sticker.R Initial commit – fresh start 2026年02月12日 13:30:26 +01:00
LICENSE.md Initial commit – fresh start 2026年02月12日 13:30:26 +01:00
NAMESPACE fix: unexport internal S7 classes and private helpers ( fix #9 ) 2026年07月02日 11:52:46 +02:00
NEWS.md chore: bump to 1.0.0 and update NEWS 2026年07月06日 20:41:18 +02:00
README.md docs: update README with multi-provider coverage and visual improvements 2026年07月02日 07:27:37 +02:00
README.Rmd docs: update README with multi-provider coverage and visual improvements 2026年07月02日 07:27:37 +02:00
rproject.toml fix: update CRAN repository URL to date 2026年06月30日 12:46:53 +02:00
rv.lock chore: sync packages 2026年06月30日 12:48:06 +02:00

AddFonts AddFonts website

Lifecycle: experimental R-CMD-check Codecov test coverage r-universe version r-universe status

Download and register fonts in R from multiple sources: Bunny Fonts (GDPR-compliant CDN), local files, direct URLs, or custom file-based providers. Fonts are cached on first use and registered via sysfonts so they work immediately with showtext and ggplot2.

Features

  • 🔒 Privacy-first default: Bunny Fonts CDN — no tracking, GDPR-compliant
  • 📂 Multiple sources: CDN providers, local files, direct URLs, or custom providers
  • 💾 Smart caching: Downloads/copies once, reuses across R sessions
  • 🎨 Full variant support: regular, bold, italic, bold-italic

Installation

# From r-universe
install.packages("AddFonts", repos = "https://gnoblet.r-universe.dev")

System Requirements

Requires woff2 command-line tool to convert fonts:

Click to see installation instructions

# Debian/Ubuntu
sudo apt install woff2
# Fedora/RHEL
sudo dnf install woff2-tools
# Arch Linux
sudo pacman -S woff2
# macOS
brew install woff2
# Windows or else
# Compile from: https://github.com/google/woff2

Quick Start

Add Fonts With One Core Function

To add a font to R, simply call add_font() with the font family name retrieved from the Bunny Fonts website. For example, to add the "Oswald" font:

library(AddFonts)
# Download and register Oswald font
add_font("oswald")
#> ✔ Converted '/home/gnoblet/.cache/AddFonts/bunny-oswald-latin-400-normal.woff2' to TTF: '/home/gnoblet/.cache/AddFonts/bunny-oswald-latin-400-normal.ttf'
#> ✔ Downloaded variant: 'bunny-oswald-latin-400-normal.ttf'
#> ✔ Converted '/home/gnoblet/.cache/AddFonts/bunny-oswald-latin-700-normal.woff2' to TTF: '/home/gnoblet/.cache/AddFonts/bunny-oswald-latin-700-normal.ttf'
#> ✔ Downloaded variant: 'bunny-oswald-latin-700-normal.ttf'
#> ✔ Font "oswald" registered and added to cache.

Preview Fonts

The preview_font() function plots all downloaded and registered variants of a font family in one go. Once you have picked a font, for instance "Merriweather", calling the preview_font() function will show you all its variants, and "Merriweather" has 4: regular, bold, italic, and bold-italic.

library(AddFonts)
preview_font("merriweather", regular.wt = 400, bold.wt = 700)

Add Fonts And Use With ggplot2

Once fonts are registered, they can be used in ggplot2 via showtext. Here we download three fonts and display them in a plot:

library(AddFonts)
library(showtext)
library(ggplot2)
fonts <- c("oswald", "merriweather", "playfair-display")
for (font in fonts) {
 add_font(font)
}
showtext_auto()
font_data <- data.frame(
 x = 0.5,
 y = seq(0.75, 0.25, length.out = length(fonts)),
 label = paste(tools::toTitleCase(gsub("-", " ", fonts)), "Font"),
 family = fonts,
 size = c(9, 8, 8)
)
ggplot(
 font_data,
 aes(x = x, y = y, label = label, family = family, size = size)
) +
 geom_text(hjust = 0.5) +
 scale_size_identity() +
 xlim(0, 1) +
 ylim(0, 1) +
 theme_void()

Cache Management

Fonts are stored in a user-level cache directory. Use these functions to inspect or clear the cache if you need to free disk space or force a re-download.

# Show cache location
get_cache_dir()
# Remove a specific font
cache_clean(families = c("oswald"))
# Clear everything
cache_clean(reset = TRUE)

Providers

add_font() supports several font sources via the provider argument.

Bunny Fonts (default)

The default provider. Supply the font family name as it appears on fonts.bunny.net:

add_font("oswald")

Local files

Pass absolute paths to TTF or OTF files already on disk:

add_font(
 "my-font",
 provider = "file",
 variants = list(
 regular = "/path/to/MyFont-Regular.ttf",
 bold = "/path/to/MyFont-Bold.ttf"
 )
)

Direct URLs

Download from any URL — no provider account needed:

add_font(
 "my-font",
 provider = "url",
 variants = list(
 regular = "https://example.com/fonts/MyFont-Regular.ttf"
 )
)

Custom file-based providers

Use FontProviderFile() for CDN providers that serve static font files (e.g. Bye Bye Binary):

bbb <- FontProviderFile(
 source = "bbb",
 base_url = "https://bye.bye.binary.com/fonts/{family}/{filename}.ttf"
)
add_font(
 "alpaga",
 provider = bbb,
 variants = list(regular = "Alpaga-Regular", bold = "Alpaga-Bold")
)

Why Bunny Fonts?

Bunny Fonts is the default provider because it mirrors most of Google Fonts with no tracking and no data collection — important for EU users and privacy-conscious projects. It has a fast global CDN and is free and open-source.

For other font sources, see the Providers section above.

How AddFonts Works

add_font() follows the same three steps for every provider:

  1. Check cache — if the font is already on disk, register it immediately and return
  2. Fetch — download from a CDN, copy from a local path, or fetch from a URL; for Bunny Fonts, also converts WOFF2 → TTF (R’s sysfonts requires TTF format)
  3. Register — calls sysfonts::font_add() so the font is available in all graphics devices via showtext

In the background, S7 classes manage provider metadata and cache entries.

  • showtext - Using fonts in R graphics
  • sysfonts - Loading fonts into R
  • S7 - a new OO system for R
  • see also pyfonts for registering fonts in Python (made by Joseph Barbier).

License

GPL (>= 3) — see LICENSE