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

Redirecting stdin during knitting alternatively providing knitr::is_interactive #926

Closed
gforge opened this issue Jan 1, 2015 · 4 comments
Milestone

Comments

@gforge
Copy link

gforge commented Jan 1, 2015

I currently use the base::interactive() to see if I should output to the viewer or to the stdout in case the document is being knitted for my htmlTable:::print.htmlTable. This works great in RStudio but I noticed that with devtools::build_vignettes the tables in the vignette are outputted to the viewer instead of into the document. I have currently solved this by using options(interactive = FALSE) but it seems clumsy and I wonder if you would consider either:

  1. Redirecting stdin during knitting (not sure this is possible)
  2. Providing a knitr::is_interactive function that I could rely on to check if the document is being knitted.
@yihui
Copy link
Owner

yihui commented Jan 2, 2015

You can check isTRUE(getOption('knitr.in.progress')):

knitr.in.progress = TRUE, device = pdf_null

But it seems to me that this is not an appropriate way to go. The better way is to define the knit_print.htmlTable method: http://cran.rstudio.com/web/packages/knitr/vignettes/knit_print.html

@yihui yihui closed this as completed Jan 2, 2015
@yihui yihui added this to the v1.9 milestone Jan 2, 2015
@gforge
Copy link
Author

gforge commented Jan 2, 2015

Thank you! Works like a charm - sorry for missing this amazing feature. I was actually not aware that it was possible to change print().

I'm considering extending my htmlTable to LaTeX & markdown (although the latter will naturally have a rather crude layout). Have you considered adding an knit_print argument output that indicates the final target output, i.e. html/markdown/latex?

@yihui
Copy link
Owner

yihui commented Jan 2, 2015

You need to check opts_knit$get('rmarkdown.pandoc.to') to see if it is R Markdown v2; if it is not, then check opts_knit$get('out.format') to see what the output type is, e.g. https://github.com/yihui/printr/blob/master/R/help.R#L36-L38 (note you may not use pandoc_to or out_format() since they are not exported, and R CMD check may complain if you do)

@github-actions
Copy link

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants