require_font {systemfonts} | R Documentation |
Ensure font availability in a script
Description
When running a script on a different machine you are not always in control of
which fonts are installed on the system and thus how graphics created by the
script ends up looking. require_font()
is a way to specify your font
requirements for a script. It will look at the available fonts and if the
required font family is not present it will attempt to fetch it from one of
the given repositories (in the order given). If that fails, it will either
throw an error or, if fallback
is given, provide an alias for the fallback
so it maps to the required font.
Usage
require_font(
family,
fallback = NULL,
dir = tempdir(),
repositories = c("Google Fonts", "Font Squirrel"),
error = TRUE
)
Arguments
family |
The font family to require |
fallback |
An available font to fall back to if |
dir |
The location to put the font file downloaded from repositories |
repositories |
The repositories to search for the font in case it is not
available on the system. They will be tried in the order given. Currently
only |
error |
Should the function throw an error if unsuccessful? |
Value
Invisibly TRUE
if the font is available or FALSE
if not (this can
only be returned if error = FALSE
)
Examples
# Should always work
require_font("sans")