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

Support knit_print in R Notebooks #1626

Open
jmcphers opened this issue Oct 18, 2017 · 1 comment
Open

Support knit_print in R Notebooks #1626

jmcphers opened this issue Oct 18, 2017 · 1 comment

Comments

@jmcphers
Copy link
Member

@jmcphers jmcphers commented Oct 18, 2017

Currently, anything emitted in the notebook gets printed exactly as it would at the console. That console output is captured and saved inside the notebook.

While this makes notebook execution symmetric with line-by-line execution of an R script or code chunk, it makes it asymmetric with knitting. When knitting, the S3 method knit_print can be used to customize how objects are emitted to the document. We could invoke that same method ourselves so that knit_print works in the notebook, too.

Example of current behavior:

image

Via Twitter thread: https://twitter.com/klmr/status/920606977671262208

@cderv
Copy link
Collaborator

@cderv cderv commented Jan 13, 2021

I believe this has impact on old issue like rstudio/rmarkdown#964

For R Markdown, usually people follow the advice in https://cran.r-project.org/web/packages/knitr/vignettes/knit_print.html#for-package-authors or now https://bookdown.org/yihui/rmarkdown-cookbook/opts-render.html to have a knit_print method.

However, this will not be enough to have something shown in the IDE when not knitting but executing chunk by chunk.

It seems the chunk execution uses print() and not knit_print() so package author must find a way to have their print method behave correctly. It is not the case as the issue linked here when you open some HTML in the IDE viewer.

The IDE override some print method for some specific classes (here and here which makes it work out of the box for object using knit_asis class, or htmlwidgets, html, knit_kable and other.

Maybe a trick can be build to have package authors create print method that works for R console and R notebook but it will always be different that using knit_print.

Just trying to resurface this question so we decide for the best way to handle this and document or fix it.

FYI @yihui if you have thought on all this.

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

No branches or pull requests

4 participants