简体   繁体   中英

Error in creating PDF file from R Markdown (Failed with error 43)

I am trying to create a PDF file using R Markdown. I received error 43 when I ran it. I tried create word file and HTML using R Markdown and it works fine. Only the PDF file does not work.

processing file: Test_New.Rmd
  |......................                                           |  33%
  ordinary text without R code

  |...........................................                      |  67%
label: unnamed-chunk-1 (with options) 
List of 1
 $ tidy: logi TRUE

  |.................................................................| 100%
  ordinary text without R code


/Applications/RStudio.app/Contents/MacOS/pandoc/pandoc +RTS -K512m -RTS 
Test_New.utf8.md --to latex --from 
markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --
output Test_New.pdf --template/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rmarkdown/rmd/latex/default-1.17.0.2.tex --highlight-style tango --latex-engine /usr/local/bin/pdflatex --variable graphics=yes --variable 'geometry:margin=1in' 
output file: Test_New.knit.md

dyld: Library not loaded: /usr/local/lib/libjpeg.8.dylib
  Referenced from: /usr/local/bin/pdflatex
  Reason: image not found

pandoc: Error producing PDF
Error: pandoc document conversion failed with error 43
Execution halted

My code on R Markdown is the following.

---
title: "Test R Markdown"
author: "Sam Ng"
date: "September 1, 2017"
output:
  pdf_document: default
  html_document: default
  word_document: default
---

# 1. R commands

Testing R commands

```{r,tidy=TRUE}
vector=c(1,2,3) # Create a new vector with three entries
max(vector) # Returns the maximum of a vector
min(vector) # Returns the minimum of a vector

```

I spent hours trying to resolve this. I installed Miktex, but was unable to get the packages directly from the package manager due to sitting behind a firewall at work. I finally was able to resolve this using the following steps:

  1. Install Miktex
  2. Create a folder to install Miktex packages, eg "C:\\miktex_pkgs"
  3. Go to the CTAN package archive and download the following .tar.lzma files:

-fancyvrb
-framed
-microtype
-miktex-zzdb1-2.9
-miktex-zzdb2-2.9
-mptopdf
-titling
-upquote
-url

  1. Move the above .tar.lzma files to the "C:\\miktex_pkgs" folder
  2. Set your packages to download from the local repository: "C:\\miktex_pkgs". To do this, go to:

    • "Miktex Settings" - this is an application
    • Click Packages
    • Change Package Repository to "C:\\miktex_pkgs"
  3. Go to "Miktex Package Manager" application and install the following packages by right-click, install:

    • List item
    • fancyvrb
    • framed
    • microtype
    • mptopdf
    • titling
    • upquote
    • url

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