我认为我的问题很简单,可以在没有MRE的情况下回答。这是抛出错误的代码:
DSP %>%
kable(format = "latex",
digits = 2,
booktabs = T,
format.args = list(big.mark = ',')) %>%
kable_styling(font_size = 9,latex_options = c("striped", "scale_down")) %>%
column_spec(1, bold = TRUE) %>%
column_spec(10, bold = TRUE) %>%
row_spec(nrow(DSP), bold = T)
我在RMarkdown文件中运行它,我在FOR循环中执行,i = 50.换句话说,数据帧DSP重新生成50次,每次它有不同的数量行。 DSP总是有10列。
我想在最后一行加粗。
对于i = 1,nrows = 14.没问题。对于i = 2,nrows = 10.没问题。对于i = 3,nrows = 9.我得到了这个:
/Applications/RStudio.app/Contents/MacOS/pandoc/pandoc +RTS -K512m -RTS statement_merge.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output pandoc1246b13bd105f.pdf --template /Users/steve-guest/Library/R/3.4/library/rmarkdown/rmd/latex/default-1.17.0.2.tex --highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable 'geometry:margin=1in'
! Package array Error: Illegal pream-token (N): `c' used.
See the array package documentation for explanation.
Type H <return> for immediate help.
...
l.123 \end{tabular}}
pandoc: Error producing PDF
Error: pandoc document conversion failed with error 43
In addition: Warning messages:
1: Removed 7 rows containing missing values (position_stack).
2: Removed 33 rows containing missing values (position_stack).
3: Removed 7 rows containing missing values (position_stack).
4: Removed 22 rows containing missing values (position_stack).
5: Removed 5 rows containing missing values (position_stack).
6: Removed 8 rows containing missing values (position_stack).
如果我然后将nrow(DSP)
替换为数字9并调用render()
语句,它仍会失败,但会显示不同的错误消息:
output file: statement_merge.knit.md
/Applications/RStudio.app/Contents/MacOS/pandoc/pandoc +RTS -K512m -RTS statement_merge.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output pandoc1246b295881e6.pdf --template /Users/steve-guest/Library/R/3.4/library/rmarkdown/rmd/latex/default-1.17.0.2.tex --highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable 'geometry:margin=1in'
! Package array Error: Illegal pream-token (N): `c' used.
See the array package documentation for explanation.
Type H <return> for immediate help.
...
l.123 \end{tabular}}
pandoc: Error producing PDF
Error: pandoc document conversion failed with error 43
In addition: Warning messages:
1: Removed 5 rows containing missing values (position_stack).
2: Removed 8 rows containing missing values (position_stack).
有谁知道为什么会这样?甚至更好,我如何解决它?
谢谢!
编辑:pandoc标题
---
output:
pdf_document:
fig_caption: false
header-includes:
- \usepackage{booktabs}
- \usepackage{longtable}
- \usepackage{array}
- \usepackage{multirow}
- \usepackage[table]{xcolor}
- \usepackage{wrapfig}
- \usepackage{float}
- \usepackage{colortbl}
- \usepackage{pdflscape}
- \usepackage{tabu}
- \usepackage{threeparttable}
- \definecolor{ufogrn}{rgb}{.2,.3,.1}
---
答案 0 :(得分:1)
我认为尝试分解您的管道并确定问题的来源是一个好习惯。我有同样的问题,在我的情况下,它来自
当我意外格式化不存在的列时kableExtra::column_spec()
。
当您收到来自LaTex的错误消息时,这表示格式化时出现问题,并且在哪里并不总是非常直观。您的管道从数据集开始,并通过每个步骤中的kable
和kableExtra
函数向数据添加一些乳胶标记。如果您确定哪个步骤导致问题,您通常可以轻松找到原因。