Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make functionality modular #38

Open
burgerga opened this issue Sep 5, 2019 · 4 comments
Open

Make functionality modular #38

burgerga opened this issue Sep 5, 2019 · 4 comments

Comments

@burgerga
Copy link

burgerga commented Sep 5, 2019

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
Copy link
Contributor

cderv commented Sep 5, 2019

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
Copy link
Author

burgerga commented Sep 5, 2019

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

@cderv
Copy link
Contributor

cderv commented Sep 6, 2019

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

@burgerga
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants