There are quite a few systems for font management in R. A key part of our work is trying to make graphs and tables cross platform reproducible, and consistent. This means dealing with fonts across different platforms.
Transparently ensure a font is available
Instead of specifying a font family as a character in a call to
ggplot, we can use a check_font()
call which tries to find
the font on your system and if not available downloads it from Google
fonts or Brick and registers it with systemfonts
, returning
the family name.
ggplot rendering uses systemfonts
and attempts to make
the output portable for use by embedding webfonts into the svg outputs.
if the sub
option is TRUE
,
check_font()
will guess an alternative.
check_font("Helvetica")
## Helvetica
## "Helvetica"
Check what fonts are available
Find out what fonts ggrrr
can find on this system.
# list all available fonts
tmp = fonts_available()
# Check if specific fonts are available. Returns
fonts_available(c("Roboto","Arial","Helvetica"))
## [1] "Roboto" "Arial" "Helvetica"
Download a font from webfont providers
Checks if a local font is available. If not downloads and installs
the font and registers in the systemfonts
packages.
Currently supported are google
and brick
# clears any registered fonts
reset_fonts()
## This wipes font databases created by `systemfonts`, `extrafonts` and `ggrrr`.
## These will be rebuilt on demand by `ggrrr`.
## N.b. This will NOT remove any custom fonts installed on your system by `ggrrr`.Are you sure? (yes/No/cancel)
# if the fonts is named the names are used for the family on this system
check_font(c("Roboto","Arial","Kings","EB Garamond"))
## Roboto Arial Kings EB Garamond
## "Roboto" "Arial" "Kings" "EB Garamond"
systemfonts::registry_fonts()
## # A tibble: 0 × 7
## # ℹ 7 variables: path <chr>, index <int>, family <chr>, style <chr>,
## # weight <ord>, italic <lgl>, features <list>