I have been trying to work with RMarkdown more and use it for communication with my team (who are not R users), and to that end, I've been trying to do reports out to PDF. I've been creating tables with kable(), but found that additional formatting is necessary, so I've been trying to work with kableExtra, but find that it hangs on the rendering of the PDF.
Below is my simplified RMarkdown file. Although I want to use kable_styling(), I have it commented out here, and what is bothering me is that the PDF will or won't render solely based on whether library(kableExtra) is included or not. I'm not even using the kableExtra functions -- just calling the library causes failure to render.
(Note: Below I have removed the closing "```" from the code chunks in order to show the file as close as possible.)
---
title: "Troubleshooting RMarkdown to PDF"
author: "Scott Jackson <br/> Frustrated RMarkdown Learner"
date: "`r format(Sys.Date(), '%B %d, %Y')`"
output: pdf_document
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
library(knitr)
library(kableExtra) # If you comment out this line, the PDF will render; as-is though, it never completes the render.
library(tidyverse)
knitr::opts_chunk$set(echo = FALSE)
options(knitr.table.format = "latex")
## A Simple Test
Running this next chuck works when run interactively, but not when knit to a PDF.
```{r test}
mtcars[1:5, 1:4] %>%
kable(col.names =c("MPG", "# Cyl", "Displacement", "Horsepower"),
caption = "mtcars example") #%>%
# kable_styling(font_size = 12)
Thank you. I had trouble putting the ``` into the OP since I'm trying to write RMarkdown inside of regular Markdown (worlds colliding, etc.). On my computer, I was using backticks ``` (Oh, I just realized that maybe I can just escape them with a backslash???) to properly delineate the code chunks, but not sure how to show that in these posts.
I can run the code interactively, too. It's when I knit to PDF it fails when library(kableExtra) is called (but not used.
There's no error message. I just get that "Render" tab with a very small "churning" circle like it is working, but it never ends. It's the screenshot I posted at the end. It just renders forever without end.
And, if I just comment out library(kableExtra) from the file (which isn't being used since I have already commented out the kable_styling() function that comes from that package -- the file will knit just fine to PDF. So I'm just perplexed why the inclusion of kableExtra prevents the knitting.
---
title: "Troubleshooting RMarkdown to PDF"
author: "Scott Jackson <br/> Frustrated RMarkdown Learner"
date: "`r format(Sys.Date(), '%B %d, %Y')`"
output:
pdf_document:
keep_md: true
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
library(knitr)
library(kableExtra) # If you comment out this line, the PDF will render; as-is though, it never completes the render.
library(tidyverse)
knitr::opts_chunk$set(echo = FALSE)
options(knitr.table.format = "latex")
```
## A Simple Test
Running this next chuck works when run interactively, but not when knit to a PDF.
```{r test}
mtcars[1:5, 1:4] %>%
kable(col.names =c("MPG", "# Cyl", "Displacement", "Horsepower"),
caption = "mtcars example") %>%
kable_styling(font_size = 12)
```
kableExtra will modify knitr::kable() default as soon as you load it. This is explained in their doc: