0

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?

eipi10
  • 91,525
  • 24
  • 209
  • 285
Alex Bădoi
  • 830
  • 2
  • 9
  • 24
  • 1
    The proper option name is `markdown` (not `rmarkdown`). Does this answer your question? – CL. Oct 10 '17 at 12:48
  • 1
    kableExtra only works if you set the format as "latex" or "html". If you don't see any table outputs from your 2nd chunk, are you trying to render it inside a HTML document? – Hao Oct 10 '17 at 14:35
  • @Hao If I understand correctly the new manual ("awesome table in pdf", 2018-05-21, p.2) this is not necessary anymore. – petzi May 27 '18 at 09:55
  • @petzi yes, with the latest version, you no longer need “latex” in kable. Thanks for providing the updated answer! – Hao May 28 '18 at 03:53

1 Answers1

4

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.

petzi
  • 1,430
  • 1
  • 17
  • 32