You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

R Sweave(Rnw)无法生成PDF文件,退出码1求助

Sweave fails to generate PDF with exit code 1 (rMarkdown works fine)

I've been working on migrating some code chunks from rMarkdown to Sweave recently, and suddenly ran into a problem: Sweave can no longer generate PDFs in RStudio, returning exit code 1 every time, but rMarkdown still works perfectly. I've searched through over a dozen similar issues online, but none of the suggested fixes have resolved my problem.

Things I've already tried:

  • Modified the system %PATH% environment variable to ensure the LaTeX path is correctly included
  • Uninstalled and reinstalled both RStudio and MiKTeX (I'm using MiKTeX 2.9, not 1.9)
  • Manually set the LaTeX path directly in the RStudio console
  • Tried compiling with knitr instead of Sweave
  • Enabled shell escape commands

Minimal Reproducible Rnw Code

\documentclass{article}
\begin{document}
\SweaveOpts{concordance=TRUE}
Hello world
\end{document}

Compilation Output

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:/PROGRA1/MIKTEX1.9/miktex/bin/x64/pdflatex.exe (exit code 1)
Note: The path shows "MIKTEX~1.9" but I'm actually using MiKTeX 2.9 — this appears to be a short path naming quirk.

Relevant Log File Content

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
)

What's confusing is that Sweave worked perfectly fine before — this issue popped up suddenly after running a simple script. My immediate goal is to get this minimal "hello world" example working so I can proceed with migrating my code. Any suggestions or insights would be greatly appreciated!

内容的提问来源于stack exchange,提问作者Will Queen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 06:36:46