I've written a function to share among colleagues for graphing, and my organization prefers Calibri to the ggplot2 default Arial for the text. If I were the only person who'd be using this function, I would first do this at the top of my script:
library(extrafont)
font_import()
loadfonts(device="win")
and then make my ggplot2 graph. I seem to only have to do font_import()
once on a given machine, but then I need to do loadfonts(device="win")
each time I start a new session. I'm not terribly well versed in what these do, but if I don't do the loadfonts
step, my graph doesn't use Calibri.
I'd like the graphing function I wrote to work for others, and I'd like to check whether they've already done these steps and give them a helpful message about it if they haven't. I thought I could use fonts()
and then check whether Calibri was listed in the output, but I think that only checks what fonts I've ever loaded with font_import()
in the history of using this machine. I also thought maybe
systemfonts::match_font("Calibri")
would check, but I get the same result regardless of whether I've already run loadfonts(...
, so that's not it, either.
How do you check whether a font is ready to be used in a graph?
showtext
instead to use the Calibri font on others' computers without needing the extrafont::loadfonts step. – Zrikenames(grDevices::windowsFonts())
. – Rugoseshowtext
do? What package is that from? I can't find it. – Seltzerinstall.packages("showtext"); library(showtext); list_of_fonts <- as.data.frame(font_files()); grep(pattern = "Calibri", x = list_of_fonts$family, ignore.case = TRUE, value = TRUE)
– Dulcia