简体   繁体   English

在Rmarkdown中从Knit转换为pdf时出错

[英]Error when converting from Knit to pdf in Rmarkdown

Code

```{r, eval=TRUE}
library(caret)

plot(iris$Sepal.Length)
```

Error reported 报告错误

pandoc.exe: pdflatex not found. pandoc.exe:找不到pdflatex。 pdflatex is needed for pdf output. pdflatex对于pdf输出是必需的。 Error: pandoc document conversion failed with error 41 In addition: Warning message: running command '"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS t4.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output t4.pdf --template "C:\\Users\\15235330\\Documents\\R\\R-3.3.0\\library\\rmarkdown\\rmd\\latex\\default-1.15.2.tex" --highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable "geometry:margin=1in"' had status 41 Execution halted No TeX installation detected (TeX is required to create PDF output). 错误:pandoc文档转换失败,错误41,另外:警告消息:运行命令'“ C:/ Program Files / RStudio / bin / pandoc / pandoc” + RTS -K512m -RTS t4.utf8.md-至乳胶-来自markdown + autolink_bare_uris + ascii_identifiers + tex_math_single_backslash-输出t4.pdf-模板“ C:\\ Users \\ 15235330 \\ Documents \\ R \\ R-3.3.0 \\ library \\ rmarkdown \\ rmd \\ latex \\ default-1.15.2.tex “ --highlight-style探戈--latex-engine pdflatex --variable graphics = yes --variable” geometry:margin = 1in“'的状态为41。执行中止没有检测到TeX安装(创建PDF输出需要TeX)。 You should install a recommended TeX distribution for your platform: Windows: MiKTeX (Complete) - http://miktex.org/2.9/setup (NOTE: Be sure to download the Complete rather than Basic installation) Mac OS X: TexLive 2013 (Full) - http://tug.org/mactex/ (NOTE: Download with Safari rather than Chrome _strongly_ recommended) Linux: Use system package manager 你应该安装你的平台推荐的TeX的分布:对于Windows:MIKTEX(完成) - http://miktex.org/2.9/setup (注:一定要下载完整的,而不是基本安装)的Mac OS X:2013的texlive(全) - http://tug.org/mactex/ (注:下载使用,而不是Chrome的_strongly_建议Safari浏览器)的Linux:使用系统包管理器

After getting a new computer, I found this post I wrote a year ago, and the technique I documented below still worked. 买了一台新计算机后,我发现了我一年前写的这篇文章,下面记录的技术仍然有效。 However my original instructions were not clear, and I have updated to hopefully help others having the same challenge. 但是,我的原始说明尚不清楚,因此我进行了更新,希望可以帮助其他面临相同挑战的人。 Of course, YMMV. 当然是YMMV。

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. 我安装了Miktex,但是由于正坐在防火墙后面而无法直接从软件包管理器中获取软件包。 I finally was able to resolve this using the following steps: 我终于能够使用以下步骤解决此问题:

  1. Install Miktex 安装Miktex
    • I used the basic installer 我使用了基本的安装程序
  2. Create a folder to install Miktex packages, eg "C:\\miktex_pkgs" 创建一个文件夹来安装Miktex软件包,例如“ C:\\ miktex_pkgs”
  3. Go to the CTAN package archive and download the following .tar.lzma files: 转到CTAN软件包存档并下载以下.tar.lzma文件:

    • fancyvrb 幻想曲
    • framed 装裱
    • microtype 微型
    • miktex-zzdb1-2.9 miktex-zzdb1-2.9
    • miktex-zzdb2-2.9 miktex-zzdb2-2.9
    • mptopdf mptopdf
    • titling 头衔
    • upquote 向上报价
    • url 网址
  4. After downloading the above files, move the above .tar.lzma files to the folder you created, eg "C:\\miktex_pkgs" 下载以上文件后,将以上.tar.lzma文件移动到您创建的文件夹中,例如“ C:\\ miktex_pkgs”

  5. Open the MikTex Console Application downloaded in Step 1 打开在步骤1中下载的MikTex控制台应用程序
    • Select "Packages" 选择“包裹”
    • Click "Install From" drop down 点击“安装自”下拉菜单
    • Click "change" 点击“更改”
    • Select "Local package repository (file system)" 选择“本地软件包存储库(文件系统)”
    • Click "Next", 点击下一步”,
    • Choose the folder you downloaded the .tar.lzma files to in Step 3 在步骤3中选择将.tar.lzma文件下载到的文件夹
    • Click "Finish" 点击“完成”
    • Click the "Update DB" logo next to the + - tool icons 单击+-工具图标旁边的“更新数据库”徽标。
    • Give a little bit of time to update. 给一点时间来更新。
  6. The packages should now show in the package list in the Miktex Console 软件包现在应该显示在Miktex控制台的软件包列表中
  7. Close R studio out and re open. 关闭R studio,然后重新打开。

Now you should be able to knit as PDF. 现在,您应该可以将其编织为PDF了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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