问题
When I knit my R Markdown document to pdf, some of my pages have this Error
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y,
: See screenshot below. What could be the problem? I am not using any new fonts and the laptop is a mac.
回答1:
You are using an en-dash; for some reason there are specific bugs for this character. See
R -e 'library(ggplot2); qplot(Sepal.Length, Petal.Length, data=iris, main="Big–booté")'
open Rplots.pdf
As you can see, the “é” characters are processed correctly but the en-dashes get turned into dots. Presumably, some R code is attempting to kludge things up by folding the characters back into some obsolete, platform-specific character set; and failing on special characters such as the en-dash.
Switching the png or cairo_pdf output driver fixes the problem (at least on Mac OS X and the latest R version 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
Or as far as Rmarkdown is concerned,
R -e 'rmarkdown::render("foo.Rmd", "pdf_document", output_file="foo.pdf", runtime = "static", output_options = list(dev = "cairo_pdf"))'
回答2:
You may need to set pdf.options(encoding = )
in a previous code chunk (or in the first code chunk in your document). Since you didn't provide a reproducible example, there is no way for us to tell which encoding is appropriate in your case. See this article for more info.
来源:https://stackoverflow.com/questions/63985427/warning-in-grid-callc-textbounds-as-graphicsannotxlabel-xx-xy