Is it possible to instruct Rmarkdown to default all tables to my styled output? Here is my attempt:
---
title: 'Test Kable Global Styling'
output:
html_document:
df_print: kable
---
```{r}
library(knitr)
library(kableExtra)
kable <- function(data) {
message("YES, IT BITES! (not sortable, but styled.)\n")
knitr::kable(data, digits=3) %>% kable_styling(bootstrap_options = "striped", full_width = F, position = "center")
}
```
## Testing
```{r}
d <- data.frame( x=1:3, y=rnorm(3) )
```
### Explicit Invokation
```{r}
kable(d)
```
### Implicit Invokation Fails
```{r}
d
```
The output looks like this:
[possibly related to How to set knitr::kable() global options in markdown for reuse, but defining my own kable function is not enough for Rmarkdown to select it.
thanks, mystery user for the complete solved update to the above problem. alas, could it generalize to :
```{r}
library(knitr)
library(DT); p <- function(...) DT::datatable(...)
knit_print.data.frame <- function(x, ...) asis_output( paste( c("",p(x)) , collapse="\n" ) )
registerS3method("knit_print", "data.frame", knit_print.data.frame)
```
# Test Code
```{r}
d <- data.frame( x=1:3, y=rnorm(3) )
```
## Print
```{r}
p(d)
d
```
done