rmd/ragg - font available when knitting, but not when running chunk

hello,

i am encountering the following issue:

i have a rmd document with chunks including ggplots. The chunks' device is set to "ragg_png" (as is the global option in RStudio; ragg and systemfont packages are installed). In the plots I am using a custom font, installed from Google fonts.

When knitting the document, the plot comes out as intended. The font is properly rendered. However, when simply running the chunk, I get the info that "font family not found in Windows font database".

Any idea how to address this? How can the font be found when knitting the document, but be missing when running the chunk? Any help? Many thanks!

Hi,

Can you share an example Rmd that reproduce the error so that we can look into it ?

Thanks you.

Hi,

many thanks for your swift reaction.

Since reprex doesn't really work with rmds, here a gist font.rmd · GitHub
It's a simple rmd, nothing special.

When checking for the availability of the font with systemfonts::match_font(family="Caveat") I get the following response:

Am I a misunderstanding something?

## $path
## [1] "C:\\Users\\__me__\\AppData\\Local\\Microsoft\\Windows\\Fonts\\Caveat-Regular.ttf"
## 
## $index
## [1] 0
## 
## $features
## NULL

It seems I don't have the same font on my system

> systemfonts::match_font("Caveat")
$path
[1] "C:\\WINDOWS\\Fonts\\arial.ttf"

$index
[1] 0

$features
NULL

but I can reproduce the error you see in RStudio.

It is possible that RStudio does not use this ragg device when you run a code chunk

I can't help much with this, and I don't think this is a rmarkdown issue.
Does the ggplot code works when you run it in a R console ?

many thanks. yes, the plot is produced as intended when eg i start a new session and create the plot from the console.

Then I don't really know. I feel this is a RStudio thing and i'll change the tag so that it is seen there.

You can also open an issue in the RStudio repo if you have a reproducible example and all information to share about your environment.

1 Like

Just noted the following: The error only appears when I use "chunk output inline" as option; if I use "chunk output in console" there is no error.

So this is definitely something related to the IDE - I would suggest opening an issue in the github repo there with step to reproduce for them to look into.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.