2

My Rmarkdown doesn't recognize the _ in kable_styling when I run the Knit to compile the Pdf or Html.

I've updated the packages(including tinytex and pandoc) as recommended at Yuhui Tinytex Debbuging and also tried to compile in different R versions (3.6.3 and 4.0.4 - 64 bits ).

Also, I tried installing the package ghostcript, but didn't find a version that matches any of my R versions.

This is the message from the error

I was unable to find any missing LaTeX packages from the error log projeto1v2.log.
! Missing $ inserted.
<inserted text> 
                $
l.227   kable_
              styling(full_width = FALSE,latex_options = "hold_position", ro...

Try to find the following text in projeto1v2.Rmd:
  kable_ 

You may need to add $ $ around a certain inline R expression ´r ´ in projeto1v2.Rmd (see the above
hint). See https://github.com/rstudio/rmarkdown/issues/385 for more info.
Erro: LaTeX failed to compile projeto1v2.tex. See https://yihui.org/tinytex/r/#debugging for
debugging tips. See projeto1v2.log for more info.
Além disso: Warning message:
In has_crop_tools() : 
Tool(s) not installed or not in PATH: ghostcript
-> As a result, figure cropping will be disabled.
Execução interrompida

A reproducible example:

library(kableExtra)
winelist <- data.frame(dados[1:12])

sumario <- round(sapply(dados, summary),2)
sumario <- t(sumario)

tabela1 <- data.frame(histograma="", sumario)

tabela1 %>%
kable(booktabs = TRUE) %>%
kable_styling(full_width = FALSE,latex_options = "hold_position", 
row_label_position='c', 
position='center') %>%
kable_paper(full_width = FALSE) %>%
column_spec(4, image = spec_hist(winelist))
     

The Dataset it's from Kaggle: Red Wine Quality

Someone know how to correct this error?

2 Answers2

0

Your code works fine for me. Just changed the column_spec to 2:

---
title: "Wine"
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE)
```

```{r tabeladados}
library(readr)
winequality_red <- read_csv("archive/winequality-red.csv")
dados <- winequality_red

library(kableExtra)
winelist <- data.frame(dados[1:12])

sumario <- round(sapply(dados, summary),2)
sumario <- t(sumario)

tabela1 <- data.frame(histograma="", sumario)

tabela1 %>%
  kable(booktabs = TRUE) %>%
  kable_styling(full_width = FALSE,latex_options = "hold_position", 
                row_label_position='c', 
                position='center') %>%
  kable_paper(full_width = FALSE) %>%
  column_spec(2, image = spec_hist(winelist))
```

-output

enter image description here

bttomio
  • 2,206
  • 1
  • 6
  • 17
  • Hey @bttomio, thanks! I know the code works fine :D. It's some issue with `_` in latex or something else. Any command or a variables name that I use `_` shows this error. For the variables name I figure out a simples solution: I don't use `_` , but in commands, like `kable_styling`, I have no other option. – Jaylhane Veloso Nunes Feb 21 '21 at 20:49
  • I thought it was related to your `kable` function. You could try this: https://stackoverflow.com/a/61743419/13249862 – bttomio Feb 21 '21 at 21:01
0

I had a similar problem, I spent maybe 10 hours trying to solve it. After a long time, the solution was to delete any variable name that use "_".