1

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. enter image description here

andy
  • 1,947
  • 5
  • 27
  • 46

2 Answers2

1

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.

Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
  • In the column, there were specific characters that threw this error. I changed it and now its working okay – andy Oct 01 '20 at 11:10
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

Té, té, té!!!

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

Thanks, John Whorfin.

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"))'
DomQ
  • 4,184
  • 38
  • 37