R-Markdown - kableExtra package - format = 'latex' not working

て烟熏妆下的殇ゞ 提交于 2019-12-12 04:59:22

问题


Using the kableExtra documentation. inside RMardown I am running:

```{r}
library(knitr)
library(kableExtra)

dt <- mtcars[1:5, 1:6]

kable(dt, format = "rmarkdown")

```

this actually outputs a table but I also get the following in the console:

    Error in kable_rmarkdown(x = c("Mazda RX4", "Mazda RX4 Wag", "Datsun 710",  : 
  could not find function "kable_rmarkdown"

when I switch to:

```{r}
library(knitr)
library(kableExtra)

dt <- mtcars[1:5, 1:6]

kable(dt, format = "latex")

```

I get no error and no table. Do I need to install latex to use this functionality?


回答1:


Just to put the comments together for providing a complete answer: The following quote is from the kableExtra vignette:

Starting from kableExtra 0.9.0, when you load this package (library(kableExtra)), it will automatically set up the global option ’knitr.table.format’ based on your current environment. Unless you are rendering a PDF, kableExtra will try to render a HTML table for you. You no longer need to manually set either the global option or the format option in each kable() function.

So you can write in both your examples (markdown and LaTeX):

library(knitr)
library(kableExtra)

dt <- mtcars[1:5, 1:6]

kable(dt)

Depending on your output format you will get the table rendered in HTML or LaTeX (PDF). And yes: For PDF you will need a LaTeX installation. But this is nowadays quite easy with TinyTeX by Yihui Xie.



来源:https://stackoverflow.com/questions/46664629/r-markdown-kableextra-package-format-latex-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!