printr icon indicating copy to clipboard operation
printr copied to clipboard

Make functionality modular

Open burgerga opened this issue 6 years ago • 4 comments

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?

burgerga avatar Sep 05 '19 09:09 burgerga

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.

cderv avatar Sep 05 '19 17:09 cderv

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

burgerga avatar Sep 05 '19 18:09 burgerga

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

cderv avatar Sep 06 '19 06:09 cderv

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

burgerga avatar Jan 12 '20 16:01 burgerga