r markdown latex compiling error (Undefined color `gray!6') with function in jtools package

Viewed 1703

I get a compiling error when trying to render an R markdown script as pdf.

Knitting the markdown file with content below with the knit button in RStudio, or running the command knitr::knit('test.Rmd'), gives an error.

---
title: "Untitled"
output: pdf_document
---

## 

```{r}
mod <- lm(speed ~ dist, data=cars)
jtools::summ(mod)
```

The error message I get is:

! LaTeX Error: Undefined color `gray!6'.

Note that when load the latex package xcolor in the preamble (as below) I get another error message but at least it compiles and renders a pdf.

---
title: "Untitled"
output: 
 pdf_document:
   extra_dependencies: ["xcolor"]
---

## 

```{r}
mod <- lm(speed ~ dist, data=cars)
jtools::summ(mod)
```

I get the same error when compiling a report from an R script. Note that I'm asking students to compile a report for a class exercise, so I don't want to lose them by having them play around with additional latex packages.

Also, apologies if this is the wrong forum, but because it's specific to an R package (things render to pdf just fine in general), it seemed like the right place for this question.

Below is my sessionInfo() in case this is helpful.

R version 4.0.2 (2020-06-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.5 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1

locale:
 [1] LC_CTYPE=en_CA.UTF-8       LC_NUMERIC=C               LC_TIME=en_CA.UTF-8        LC_COLLATE=en_CA.UTF-8     LC_MONETARY=en_CA.UTF-8   
 [6] LC_MESSAGES=en_CA.UTF-8    LC_PAPER=en_CA.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.5       rstudioapi_0.11  knitr_1.29       magrittr_1.5     tidyselect_1.1.0 munsell_0.5.0    colorspace_1.4-1 R6_2.4.1        
 [9] rlang_0.4.7      dplyr_1.0.1      tools_4.0.2      grid_4.0.2       gtable_0.3.0     xfun_0.16        htmltools_0.5.0  ellipsis_0.3.1  
[17] yaml_2.2.1       digest_0.6.25    tibble_3.0.3     lifecycle_0.2.0  crayon_1.3.4     purrr_0.3.4      ggplot2_3.3.2    jtools_2.1.0    
[25] vctrs_0.3.2      glue_1.4.1       evaluate_0.14    rmarkdown_2.3    pander_0.6.3     compiler_4.0.2   pillar_1.4.6     generics_0.0.2  
[33] scales_1.1.1     pkgconfig_2.0.3
1 Answers

I followed the "LaTeX packages used in this package" section in kableExtra's awesome_table_in_pdf vignette.

header-includes:
  - \usepackage{xcolor}

It wasn't necessary when I knitted the document normally through RStudio. But it was when I had to do some unconventional things with a shared drive. (That's when I got the "! LaTeX Error: Undefined color `gray!6'." error.)

Complete yaml header:

title: SO Question
output:
  pdf_document:
    toc: FALSE
    number_sections: TRUE
geometry: margin=2cm
header-includes:
  - \usepackage{xcolor}
Related