rmarkdown
rmarkdown copied to clipboard
Per-chunk override of global df_print specification: default, kable, tibble, or paged
Hi, I would like to override the global df_print = c("default", "kable", "tibble", "paged")
specification on a per-chunk basis. So for example, while this YAML header has df_print
set to paged
globally:
---
title: "R Notebook"
output:
html_notebook:
df_print: paged
---
I would like to be able to override this for individual chucks along the lines of:
```{r df_print = "tibble"}
diamonds
```
My Google searching suggests this was not a feature of R Markdown as of 2017-03-15, but I couldn't find any more recent information.
Would this be a reasonable feature request?
We already have some means to override the default printing of table data. Let me know if the following R Markdown example is helpful:
---
title: "DF Printing"
output:
html_document:
df_print: paged
---
paged print
```{r echo=TRUE, paged.print=TRUE}
ggplot2::diamonds
```
default output
```{r echo=TRUE, paged.print=FALSE}
ggplot2::diamonds
```
kable output
```{r echo=TRUE}
knitr::kable(ggplot2::diamonds[1:10, ])
```
This yields the following rendered HTML output:
![print_options](https://user-images.githubusercontent.com/5612024/43165643-4c07ea22-8f49-11e8-9efc-08b489f945a1.png)
Thanks for the paged.print=TRUE
tip @rich-iannone. As for the kable
output via
```{r echo=TRUE}
knitr::kable(ggplot2::diamonds[1:10, ])
```
I should've given more context: I wanted the df_print specification flexibility in the context of a bookdown .Rmd
file where:
- We present the reader with the non
knitr::kable()
code - But print the resulting output in in
kable
format
Our current non-"Don't repeat yourself" workaround is to have:
```{r eval = FALSE, echo = TRUE}
ggplot2::diamonds %>%
slice(1:10)
```
```{r eval = TRUE, echo = FALSE}
ggplot2::diamonds %>%
slice(1:10) %>%
knitr::kable()
```
However, just the paged.print=TRUE
tip goes a long way to helping @ismayc and me out. Many thanks!!
@yihui I've done pretty much what @rudeboybert has been doing for a bookdown
project (showing the code, then rendering the table from the code in two separate chunks). Is there a more DRY way of doing this?
Multiple approaches to DRY in knitr: https://yihui.name/knitr/demo/reference/ But I don't know how well they are supported in the RStudio IDE.
```{r my-data, eval = FALSE, echo = TRUE}
ggplot2::diamonds %>%
slice(1:10)
```
```{r eval = TRUE, echo = FALSE}
<<my-data>> %>%
knitr::kable()
```
Edit: in theory, we could add a chunk option in knitr to support per-chunk override of the printing method. Currently we only support paged.print = TRUE/FALSE
. I feel this could be extended.