yihui / knitr

A general-purpose tool for dynamic report generation in R
https://yihui.org/knitr/
2.36k stars 873 forks source link

default graphics device to more performant ragg #2319

Closed kidwellj closed 4 months ago

kidwellj commented 5 months ago

By filing an issue to this repo, I promise that

I understand that my issue may be closed if I don't fulfill my promises.

kidwellj commented 5 months ago

ggplot() is basically always running slow when using the default graphics device on MacOS, which becomes more painfully evident when plotting geospatial objects and others which are computationally complex. This is easily resolved (as per this thread on quarto) To resolve this, you simply need to add a block to _quarto.yml:

knitr:
  opts_chunk:
    dev: ragg_png

However I wonder if it would be prudent to simply change the default graphics device in knitr as this has already been done in ggplot (noted here.

cderv commented 5 months ago

Thanks for opening the issue!

Just adding that with R Markdown, the default graphic device is defined in the output format. It can be changed with dev option in YAML. Example for html_document

Same for Quarto where the default device is defined in the HTML format.

So even if we were to change the default in knitr, I think it requires to adapt in other tools too that may not use knitr defaults.

In all case, we probably can only change the default to ragg when the package is available, otherwise this would add a new dependency to knitr or markdown.

yihui commented 5 months ago

Thanks for the suggestion! Changing the default will affect too many users and perhaps also cause breakage (e.g., when ragg is not installed). I tend not to do it in knitr but want to let you know that you can change the default by yourself: https://yihui.org/en/2023/10/opts-chunk/