I think my problem is straightforward enough that it can be answered without a MRE. Here's the code that's throwing an error:
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)
I'm running this in an RMarkdown file, which I execute in a FOR loop, with i = 50. In other words, the data frame DSP gets re-generated 50 times, and each time it has a different number of rows. DSP always has 10 columns.
I want to bold the last row.
For i = 1, nrows = 14. No problem. For i=2, nrows= 10. No problem. For i=3, nrows = 9. I get this:
/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).
If I then replace nrow(DSP)
with the number 9 and call the render()
statement, it still fails, but with a different error message:
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).
Does anyone know why this is happening? And even better, how I can fix it?
Thanks!
EDIT: pandoc headers
---
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}
---