Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default to ragg graphics device if available for rendering #393

Closed
mfherman opened this issue Sep 3, 2021 · 4 comments
Closed

Default to ragg graphics device if available for rendering #393

mfherman opened this issue Sep 3, 2021 · 4 comments

Comments

@mfherman
Copy link

mfherman commented Sep 3, 2021

I was recently trying to make a reprex that used custom fonts and I couldn't figure out a way to specify the graphic device used for rendering the reprex. Because of this (on my Windows machine) I wasn't able to use a custom font in my ggplot reprex. Since ragg/systemfonts seems to work quite well across all OS, would it make sense to set ragg as the default graphics device for the R Markdown's rendered by reprex?

Recently, ggplot2::ggsave() made ragg the default device if it is installed.

library(ggplot2)

ggplot(mtcars, aes(mpg, cyl)) +
  geom_point() +
  theme_minimal(base_family = "Jokerman")
#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
#> found in Windows font database

#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
#> found in Windows font database
#> Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
#> family not found in Windows font database

#> Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
#> family not found in Windows font database

#> Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
#> family not found in Windows font database

#> Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
#> family not found in Windows font database

#> Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
#> family not found in Windows font database

#> Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
#> family not found in Windows font database
#> Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
#> font family not found in Windows font database

Created on 2021-09-03 by the reprex package (v2.0.0)

@yutannihilation
Copy link
Member

I agree it's nice to use ragg where possible. Just for your information, you should be able to change the graphic device by setting the chunk option. If you do not want to include the line, you can use #+ to specify include=FALSE:

#+ setup, include=FALSE
knitr::opts_chunk$set(dev = "ragg_png")

#+ main
library(ggplot2)

ggplot(mtcars, aes(mpg, cyl)) +
  geom_point() +
  theme_minimal(base_family = "Jokerman")

(I found this trick on this issue: #214. I hope setting chunk options will get easier in future....)

@mfherman
Copy link
Author

mfherman commented Sep 4, 2021

Aha! I didn't know you could set chunk options in a reprex. In that case, I'm not sure if it makes sense for reprex to change the default graphics device? Not sure if it's on the roadmap for R Markdown, but maybe they will make ragg_png the default device for render() at some point.

Thanks so much @yutannihilation!

library(ggplot2)

ggplot(mtcars, aes(mpg, cyl)) +
  geom_point() +
  theme_minimal(base_family = "Jokerman")

Created on 2021-09-04 by the reprex package (v2.0.0)

@yutannihilation
Copy link
Member

maybe they will make ragg_png the default device for render() at some point.

Ah, not sure about their plan, but this sounds better.

@jennybc
Copy link
Member

jennybc commented Sep 8, 2021

I think specifying a non-default graphics device should remain the responsibility of the user (or maybe we'll eventually inherit a different default choice from rmarkdown/knitr). In general, I try to not to sign reprex up for jobs that are unrelated to its core mission of providing convenience features around rendering small examples.

Even the ability to specify chunk options via #+ is not a reprex feature per se -- it comes from knitr directly and I just make an effort not to break that:

https://bookdown.org/yihui/rmarkdown-cookbook/spin.html

@jennybc jennybc closed this as completed Sep 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants