微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Rmarkdown 无法识别 kable_styling 命令中的内联

如何解决Rmarkdown 无法识别 kable_styling 命令中的内联

当我运行 Knit 编译 Pdf 或 Html 时,我的 Rmarkdown 无法识别 kable_styling 中的 _。

我已经按照 Yuhui Tinytex Debbuging 的建议更新了软件包(包括 tinytex 和 pandoc),并尝试在不同的 R 版本(3.6.3 和 4.0.4 - 64 位)中进行编译。

另外,我尝试安装 ghostcript 包,但没有找到与我的任何 R 版本匹配的版本。

这是错误信息

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

一个可重现的例子:

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,row_label_position='c',position='center') %>%
kable_paper(full_width = FALSE) %>%
column_spec(4,image = spec_hist(winelist))
     

来自 kaggle 的数据集:Red Wine Quality

有人知道如何纠正这个错误吗?

解决方法

你的代码对我来说很好用。刚刚将 column_spec 更改为 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))
```

-输出

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。