【问题标题】:Rmarkdown doesn't recognize the inline in kable_styling commandRmarkdown 无法识别 kable_styling 命令中的内联
【发布时间】:2021-05-24 02:30:06
【问题描述】:

当我运行 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,latex_options = "hold_position", 
row_label_position='c', 
position='center') %>%
kable_paper(full_width = FALSE) %>%
column_spec(4, image = spec_hist(winelist))
     

来自 Kaggle 的数据集:Red Wine Quality

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

【问题讨论】:

  • 请提供更多细节,欢迎提供最小可复制示例 (stackoverflow.com/questions/5963269/…)。
  • 欢迎您,@Jaylhane Veloso Nunes!能否请您提供kable 表的代码?
  • 你好@bttomio,我不知道在这种情况下它是否有用,但我会将代码添加到问题中。 (PS:大块工作正常,问题是我给针织的时候)。
  • 能否请您尝试消除开头的换行符(```{r tabeladados})?
  • 你好@bttmio,很抱歉,这是代码块中的代码。

标签: r r-markdown knitr inline blogdown


【解决方案1】:

您的代码对我来说很好用。只是将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))
```

-输出

【讨论】:

  • 嘿@bttomio,谢谢!我知道代码工作正常:D。 _ 在乳胶或其他东西中存在一些问题。我使用_ 的任何命令或变量名称都会显示此错误。对于变量名称,我想出了一个简单的解决方案:我不使用 _ ,但在命令中,例如 kable_styling,我别无选择。
  • 我认为这与您的kable 函数有关。你可以试试这个:stackoverflow.com/a/61743419/13249862
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-02-08
  • 1970-01-01
  • 2014-06-15
  • 2020-09-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多