“Compile pdf” in Rstudio works but knit2pdf does not work in R or RStudio

不羁的心 提交于 2020-01-17 07:40:52

问题


I'm hoping someone can point me to the internal setting that can fix my issue with compiling tex docs from R.

My issues is that texi2pdf and knit2pdf throw warnings and do not generate a pdf.

I can get Rnw files to compile using the "Compile pdf" button in RStudio, I can knit rnw files into text files, and I can get my tex files to compile into pdf using TeXnicCenter, but I can't get the texi2pdf or knit2pdf functions to work in R.

In Windows 7 on one machine with TexLive installed and on another machine with MikTex 2.9 installed, when I run the following:

library(knitr)
f = system.file("examples", "knitr-minimal.Rnw", package = "knitr")
knit(f)  # compile to tex
texi2pdf(gsub('Rnw', 'tex', f))

the first part works (rnw->tex), but the texi2pdf (tex->pdf) results in:

Warning message:
running command '"C:\PROGRA~2\MIKTEX~1.9\miktex\bin\texify.exe" --quiet --pdf 
"C:/Program Files/R/R-3.3.3/library/knitr/examples/knitr-minimal.tex" --max-
iterations=20 -I "C:/PROGRA~1/R/R-33~1.3/share/texmf/tex/latex" -I 
"C:/PROGRA~1/R/R-33~1.3/share/texmf/bibtex/bst"' had status 1 

The same is true if I run knit2pdf(f), I get the same warning message + a pop up "pdflatex.EXE has stopped working".

One other thing I don't understand is that I have MikTex 2.9 in my path, but the warning message references MikTex 1.9, which is not installed on my machine and is not in the path.


回答1:


This isn't so much a fix as a work around...

library(knitr)
setwd(system.file("examples", package = "knitr"))
knit("knitr-minimal.Rnw")  # compile to tex
system('pdflatex knitr-minimal.tex')



回答2:


This happened to me today, and it seems it was because MikTex 2.9 was installed under my User account. R is also installed under my User account. Here is what worked for me:

  1. Uninstall MikTex and reinstall it under Program files. Update MikTex from its console.
  2. Add "C:\Program Files\MiKTeX 2.9\miktex\bin\x64" to Windows PATH (delete the old MikTex path).
  3. Restart you computer
  4. Uninstall and reinstall the knitr package (that might not be necessary).


来源:https://stackoverflow.com/questions/44785961/compile-pdf-in-rstudio-works-but-knit2pdf-does-not-work-in-r-or-rstudio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!