另一个LaTeX错误:rmarkdown中缺少\ begin {document}

时间:2018-12-11 16:03:17

标签: r-markdown

我正在使用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()进行清理。

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

1 个答案:

答案 0 :(得分:0)

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

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

仅供参考,父级的标头不仅包含乳胶信息,还提供计算的主.R文件。

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