Make functionality modular
Thanks for this nice package. I am a teacher mainly interested in including sections of help pages in my xaringan presentations so that I can explain functions to students. However, I still want my tibbles printed in the regular way. Could you make the functionality modular so that we can choose what gets pretty-printed?
Hi,
Can you provide an example of what you want to achieve ? I am willing to help but I am not sure of the desired output.
The better is a small reproductible example to understand the undesired behavior you are observing.
It is wild guess but knitr as a render option that could be used to provide a custom function for rendering a specific chunk in a specific way. See there https://yihui.name/knitr/options/
Hope it helps.
I don't think it is possible to create a reprex with chunks, so I'll improvise. If I make an R Markdown file with the following chunks
```{r setup, include=F}
knitr::opts_chunk$set(echo = TRUE)
library(printr)
library(tibble)
```
```{r, printr.help.sections=c('usage'), comment=''}
?coef
head(as_tibble(iris))
```
I get the help text in my output, but the tibble is printed with kable
Now if I comment out library(printr), I don't get the help output, but my tibble prints as a tibble.
What I want is a mixture: I want the help output, but I want printr to leave my tibbles alone.
So in summary:
library(tibble) |
#library(tibble) |
What I want | |
|---|---|---|---|
| help section printed | T | F | T |
tibble printed with kable |
T | F | F |
Thanks a lot ! This is a very helpful reprex. I understand now what you mean by modular. I get why it could be interesting to not have all the methods loaded but I am not sure how it could be done. This will need thinking.
As a workaround, for your specific case, you could deactivate the pretty printing for a chunk, and thus for a chunk with you tibble. You can use the render option for that and set it to usual print because you are looking at basic printing
---
title: "Test"
output: html_document
---
```{r setup, include=F}
knitr::opts_chunk$set(echo = TRUE)
library(printr)
library(tibble)
```
```{r comment='', printr.help.sections=c('usage')}
?coef
```
```{r, render = print}
head(as_tibble(iris))
```
Is this what you seek for your specific case ?
More infos on pretty print in knitr: https://cran.rstudio.org/web/packages/knitr/vignettes/knit_print.html
Sorry for the late reply, but yes, exactly what I want ;)