【发布时间】:2020-09-21 02:24:04
【问题描述】:
当我将我的 R Markdown 文档编成 pdf 时,我的某些页面出现此错误
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :见下面的截图。可能是什么问题呢?我没有使用任何新字体,笔记本电脑是 Mac。
【问题讨论】:
标签: r r-markdown knitr
当我将我的 R Markdown 文档编成 pdf 时,我的某些页面出现此错误
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :见下面的截图。可能是什么问题呢?我没有使用任何新字体,笔记本电脑是 Mac。
【问题讨论】:
标签: r r-markdown knitr
您使用的是en-dash;由于某种原因,此角色存在特定的错误。见
R -e 'library(ggplot2); qplot(Sepal.Length, Petal.Length, data=iris, main="Big–booté")'
open Rplots.pdf
如您所见,“é”字符被正确处理,但短划线变成了点。据推测,一些 R 代码试图通过将字符折叠回一些过时的、特定于平台的字符集来将事情搞砸;并且在特殊字符(例如破折号)上失败。
Switching the png or cairo_pdf output driver 修复了问题(至少在 Mac OS X 和最新的 R 版本 4.0.3 上):
R -e 'png(filename = "win.png"); library(ggplot2); qplot(Sepal.Length, Petal.Length, data=iris, main="Big–boo–té"); dev.off()'
open win.png
或者就 Rmarkdown 而言,
R -e 'rmarkdown::render("foo.Rmd", "pdf_document", output_file="foo.pdf", runtime = "static", output_options = list(dev = "cairo_pdf"))'
【讨论】:
您可能需要在前一个代码块(或文档中的第一个代码块)中设置pdf.options(encoding = )。由于您没有提供可重现的示例,因此我们无法判断哪种编码适合您的情况。 See this article for more info.
【讨论】: