How to use Cairo PNGs in R Markdown

前端 未结 2 1838
不知归路
不知归路 2021-02-19 02:19

There are many advantages to using Cairo to save R graphics (see here, for example). When saving PDFs, for instance, the cairo_pdf device correctly embeds custom fo

2条回答
  •  孤城傲影
    2021-02-19 02:49

    Use knitr options, not the YAML header.

    You can use knitr options to change the type of a specific device (Yihui's recommendation):

    knitr::opts_chunk$set(dev.args = list(png = list(type = "cairo")))
    

    Alternately, you could do it conditionally based on the output:

    if (!knitr::is_latex_output()) {
      knitr::opts_chunk$set(dpi = 300, dev.args = list(type = "cairo"))
    })
    

    I've used this on a couple of documents now. Note: I've only used this for documents doing rmarkdown::render(...) from the R command line.

提交回复
热议问题