简体   繁体   中英

Error compiling PDF using RStudio/knitr with a plot

Posted this on RStudio help already but seeing if anybody here has any idea. I'm getting the following error below when I try to Knit PDF with a plot in the document using RStudio. The error does not occur when I try to Knit PDF without a plot nor does it occur when I Knit HTML with the plot. I'm on a Mac with Yosemite.

sh: line 1: 3234 Trace/BPT trap: 5 gs -dSAFER -sDEVICE=bbox -dBATCH -dNOPAUSE -c save pop -f fcmb_files/figure-latex/unnamed-chunk-2-1.pdf 2>&1 > /dev/null
!!! Error: Ghostscript exited with error code 133!
output file: fcmb.knit.md

! Undefined control sequence.
l.98 \begin{center}\includegraphics

pandoc: Error producing PDF from TeX source
Error: pandoc document conversion failed with error 43

Edit: It seems like the culprit was that the graphicx package wasn't being added for some reason. I hacked a solution by just including

header-includes: \\usepackage{graphicx}

in the front-matter of my document.

I also get the error "sh: line 1: Trace/BPT trap: 5 gs -dSAFER -sDEVICE=bbox -dBATCH -dNOPAUSE -c save pop -f .pdf 2>&1 > /dev/null !!! Error: Ghostscript exited with error code 133!"
when I use the command "pdfcrop" on a mac with Yosemite. This is because Ghostscript is broken on Yosemite: https://tug.org/mactex/yosemite.html . So you might need to install the Ghostscript 9.15 package.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM