【问题标题】:another LaTeX Error: Missing \begin{document} in rmarkdown另一个 LaTeX 错误:rmarkdown 中缺少 \begin{document}
【发布时间】:2018-12-11 16:03:16
【问题描述】:

我正在使用 rmarkdown 自动生成 pdf 报告。我使用宏来运行代码。我可以运行一次代码,它可以正常工作。当我再次调用宏时,它似乎可以工作,但是在创建 pdf 时,我收到错误“LaTeX 错误:缺少 \begin{document}”

这是我第一次得到的:

output file: L:/Statunit/morton/NCC R markdown reports/NCC Reports/NCC_Dashboard_Report_Dave.knit.md

"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS "L:/Statunit/morton/NCC R markdown reports/NCC Reports/NCC_Dashboard_Report_Dave.utf8.md" --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output pandoc9e03c3032cf.tex --template "C:\Users\Mortond\Documents\R\win-library\3.5\rmarkdown\rmd\latex\default-1.17.0.2.tex" --highlight-style tango --latex-engine xelatex --variable graphics=yes --variable "geometry:margin=1in" --variable "compact-title:yes" --include-in-header "C:\Users\Mortond\AppData\Local\Temp\Rtmp8cWvvQ\rmarkdown-str9e022b75c22.html" 

Output created: Report-254-225573.pdf

第二次,我调用相同的代码,只是更改了报告名称,所以数据相同,我得到了。

output file: L:/Statunit/morton/NCC R markdown reports/NCC Reports/NCC_Dashboard_Report_Dave.knit.md

"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS "L:/Statunit/morton/NCC R markdown reports/NCC Reports/NCC_Dashboard_Report_Dave.utf8.md" --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output pandoc9e01f0a74c5.tex --template "C:\Users\Mortond\Documents\R\win-library\3.5\rmarkdown\rmd\latex\default-1.17.0.2.tex" --highlight-style tango --latex-engine xelatex --variable graphics=yes --variable "geometry:margin=1in" --variable "compact-title:yes" 
! LaTeX Error: Missing \begin{document}.

Error: Failed to compile Report-253-225573.tex. See Report-253-225573.log for more info.

我的 YAML 是

---
    title: ''
    header-includes: 
    - \usepackage{fancyhdr}
    - \addtolength{\headheight}{1.0cm} % make more space for the header
    - \pagestyle{fancyplain} % use fancy for all pages except chapter start
    - \lhead{\includegraphics[height=1.2cm]{TJC_logo_color.png}} % left logo
    - \renewcommand{\headrulewidth}{0pt} % remove rule below header
    output:
       pdf_document: 
       latex_engine: xelatex
       word_document: default
       html_document: default
       urlcolor: blue
       classoption: landscape
---

my code that calls the markdown is :
    render_report = function(b,h,p) {
      rmarkdown::render(
       "L:/Statunit/morton/NCC R markdown reports/NCC Dashboard Report 
          Dave.Rmd", params = list(
          b1 = b,
          h1 = h,
         p1 = p
        ),
        output_file = paste0("Report-", h, "-", p, ".pdf")
      )
    }

    render_report(b="xxxx Hospital, Inc.",h='253',p='225573')

带有错误部分的日志文件是。

("C:\Users\Mortond\AppData\Local\Programs\MiKTeX 2.9\tex\latex\graphics-def\xet
ex.def"
File: xetex.def 2017/06/24 v5.0h Graphics/color driver for xetex
))
\Gin@req@height=\dimen160
\Gin@req@width=\dimen161
)
("C:\Users\Mortond\AppData\Local\Programs\MiKTeX 2.9\tex\latex\oberdiek\grffile
.sty"
Package: grffile 2017/06/30 v1.18 Extended file name support for graphics (HO)
Package grffile Info: Option `multidot' is set to `true'.
Package grffile Info: Option `extendedchars' is set to `false'.
Package grffile Info: Option `space' is set to `true'.
Package grffile Info: \Gin@ii of package `graphicx' fixed on input line 494.
)
("C:\Users\Mortond\AppData\Local\Programs\MiKTeX 2.9\tex\latex\parskip\parskip.
sty"
Package: parskip 2018-08-24 v2.0a non-zero parskip adjustments
)
("C:\Users\Mortond\AppData\Local\Programs\MiKTeX 2.9\tex\latex\titling\titling.
sty"
Package: titling 2009/09/04 v2.1d maketitle typesetting
\thanksmarkwidth=\skip53
\thanksmargin=\skip54
\droptitle=\skip55
)
("C:\Users\Mortond\AppData\Local\Programs\MiKTeX 2.9\tex\latex\fancyhdr\fancyhd
r.sty"
Package: fancyhdr 2017/06/30 v3.9a Extensive control of page headers and footer
s
\f@nch@headwidth=\skip56
\f@nch@O@elh=\skip57
\f@nch@O@erh=\skip58
\f@nch@O@olh=\skip59
\f@nch@O@orh=\skip60
\f@nch@O@elf=\skip61
\f@nch@O@erf=\skip62
\f@nch@O@olf=\skip63
\f@nch@O@orf=\skip64
)

! LaTeX Error: Missing \begin{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.90 \addtolength{\headheight}{1.0cm} \%
                                         make more space for the header 
Here is how much of TeX's memory you used:
 22493 strings out of 427767
 408844 string characters out of 3146884
 530389 words of memory out of 3000000
 26423 multiletter control sequences out of 15000+200000
 532722 words of font info for 28 fonts, out of 3000000 for 9000
 1328 hyphenation exceptions out of 8191
 45i,0n,68p,816b,443s stack positions out of 5000i,500n,10000p,200000b,50000s

No pages of output.

那么为什么它只工作一次而不是第二次呢?如果我退出 RStudio 然后再次启动它,它似乎可以工作。我试过
.rs.restartR() 无济于事。也 rm(list = ls(envir = globalenv()),envir = globalenv()) gc() 收拾东西。

有什么想法吗?感谢您阅读所有这些内容。

【问题讨论】:

  • 我可能通过不同类型的错误找到了解决方案。我尝试通过 detach("package:kableExtra", unload=TRUE)` 分离 kableextra,并且能够在同一会话中生成 2 个报告。

标签: r-markdown


【解决方案1】:

我不知道我是否有同样的问题。但是我经历过,如果我编译我的文档,它第一次工作,第二次失败。我怀疑是缓存问题并添加了cache.rebuild=T

<<echo=F, cache=T, message=F, warning=F, `>>= set_parent('../../Parent.Rnw') @

只是 FIY,父级的标题不仅包括乳胶信息,而且还包括我的主要 .R 文件的计算。

无论如何,如果有人遇到类似问题,请尝试将cache.rebuild=T 添加到您包含的脚本中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-10
    • 2017-12-07
    • 2021-05-14
    • 1970-01-01
    • 2011-04-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多