R Sweave (Rnw) won't produce a PDF file - exit code 1

只谈情不闲聊 提交于 2020-12-15 05:16:32

问题


I've recently been learning how to use sweave in R to create PDF files out of Rstudio, and my machine has suddenly stopped being able to create a PDF using sweave. It can still create PDFs in rMarkdown, but it gives the exit code one when it fails to do so in sweave.

There are maybe a dozen questions that I've found online that ask similar questions, but none of the answers have helped. I've tried changing the %PATH% in my environment window, I've uninstalled and reinstalled rStudio and Miktex, I've set the path to latex directly into the console in Rstudio, I've tried using knitr instead of sweave, and I've tried enabling shell escape commands. Unfortunately, none of these have worked.

To verify that it's not an issue with my code, I've created a simple example that runs into the same issue. Here's my Rnw code:


\documentclass{article}

\begin{document}
\SweaveOpts{concordance=TRUE}

Hello world

\end{document}

Here's the output in the Compile PDF tab (note, I have Miktex version 2.9, not 1.9):

Writing to file trash.tex
Processing code chunks with options ...
 1 : echo keep.source term verbatim (trash.Rnw:6)

You can now run (pdf)latex on 'trash.tex'
Running pdflatex.exe on trash.tex...failed
Error running C:/PROGRA~1/MIKTEX~1.9/miktex/bin/x64/pdflatex.exe (exit code 1)

And here's the log file (note that it always references miktex 2.9, not 1.9):

This is pdfTeX, Version 3.14159265-2.6-1.40.20 (MiKTeX 2.9.7000 64-bit) (preloaded format=pdflatex 2019.4.18)  19 APR 2019 09:52
entering extended mode
**./trash.tex
(trash.tex
LaTeX2e <2018-12-01>
("C:\Program Files\MiKTeX 2.9\tex/latex/base\article.cls"
Document Class: article 2018/09/03 v1.4i Standard LaTeX document class
("C:\Program Files\MiKTeX 2.9\tex/latex/base\size10.clo"
File: size10.clo 2018/09/03 v1.4i Standard LaTeX file (size option)
)
\c@part=\count80
\c@section=\count81
\c@subsection=\count82
\c@subsubsection=\count83
\c@paragraph=\count84
\c@subparagraph=\count85
\c@figure=\count86
\c@table=\count87
\abovecaptionskip=\skip41
\belowcaptionskip=\skip42
\bibindent=\dimen102
)
(C:/PROGRA~1/R/R-35~1.3/share/texmf/tex/latex\Sweave.sty
Package: Sweave 

("C:\Program Files\MiKTeX 2.9\tex/latex/base\ifthen.sty"
Package: ifthen 2014/09/29 v1.1c Standard LaTeX ifthen package (DPC)
)
("C:\Program Files\MiKTeX 2.9\tex/latex/graphics\graphicx.sty"
Package: graphicx 2017/06/01 v1.1a Enhanced LaTeX Graphics (DPC,SPQR)

("C:\Program Files\MiKTeX 2.9\tex/latex/graphics\keyval.sty"
Package: keyval 2014/10/28 v1.15 key=value parser (DPC)
\KV@toks@=\toks14
)
("C:\Program Files\MiKTeX 2.9\tex/latex/graphics\graphics.sty"
Package: graphics 2017/06/25 v1.2c Standard LaTeX Graphics (DPC,SPQR)

("C:\Program Files\MiKTeX 2.9\tex/latex/graphics\trig.sty"
Package: trig 2016/01/03 v1.10 sin cos tan (DPC)
)
("C:\Program Files\MiKTeX 2.9\tex/latex/graphics-cfg\graphics.cfg"
File: graphics.cfg 2016/06/04 v1.11 sample graphics configuration
)
Package graphics Info: Driver file: pdftex.def on input line 99.

("C:\Program Files\MiKTeX 2.9\tex/latex/graphics-def\pdftex.def"
File: pdftex.def 2018/01/08 v1.0l Graphics/color driver for pdftex
))
\Gin@req@height=\dimen103
\Gin@req@width=\dimen104
)

I was learning how to transition some of my work in codechunks from rmarkdown to sweave when the error started, so I'm just expecting to get a regular PDF saying "hello world" when the issue is fixed. What's especially puzzling is that sweave was creating PDFs just fine until I ran a simple program, and it's all been downhill since then.

Thank you in advance to any comments, suggestions, or help!


回答1:


I also happen (exit code 1). Later, when downloading or after loading MikTeX, just go to MikTeX Console => Settings => General => You can choose whether missing packages are to be installed on-the-fly : choose Always install missing packages on-the-fly. Reference from https://yihui.name/en/2018/03/miktex-auto-install/




回答2:


If anyone is reading, I figured out (at least for now) a way to get PDFs to compile. Although I had already uninstalled and reinstalled Miktex and rstudio twice each, I found a link mentioning to try installing miktek on the desktop and to turn the setting of updating packages to automatic. The link to the solution that worked for me is here



来源:https://stackoverflow.com/questions/55763116/r-sweave-rnw-wont-produce-a-pdf-file-exit-code-1

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