yihui / printr

Some (magical) printing methods for knitr
https://yihui.org/printr/
118 stars 24 forks source link

Make functionality modular #38

Open burgerga opened 5 years ago

burgerga commented 5 years ago

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?

cderv commented 5 years ago

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.

burgerga commented 5 years ago

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)
?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|
cderv commented 5 years ago

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)
?coef
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
burgerga commented 4 years ago

Sorry for the late reply, but yes, exactly what I want ;)