Skip to content

Any way to set knitr::kable() as global option for all tables in a qmd file? #933

Answered by jjallaire
jeweljohnsonj asked this question in Q&A
Discussion options

You must be logged in to vote

Here is one way to do it:

```{r}
#| include: false
knit_print.data.frame = function(x, ...) {
  res = paste(c("", "", knitr::kable(x)), collapse = "\n")
  knitr::asis_output(res)
}

registerS3method(
  "knit_print", "data.frame", knit_print.data.frame,
  envir = asNamespace("knitr")
)
```

```{r}
mtcars
```

That's the low-level way, the printr package also implements this by default:

```{r}
#| include: false
library(printr)
```

```{r}
mtcars
```

Replies: 2 comments 9 replies

Comment options

You must be logged in to vote
8 replies
@mcanouil
Comment options

@cderv
Comment options

@mcanouil
Comment options

@cderv
Comment options

@jeweljohnsonj
Comment options

Answer selected by jjallaire
Comment options

You must be logged in to vote
1 reply
@jeweljohnsonj
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants