yihui / printr

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

Add knit_print method for sessionInfo #26

Open billdenney opened 7 years ago

billdenney commented 7 years ago

This makes sessionInfo look better in markdown documents by changing the output to a nested unnumbered list. It provides a bit more information for packages installed from GitHub via devtools by giving the SHA1 hash for those packages.

yihui commented 7 years ago

Could you show me an output sample? Thanks!

billdenney commented 7 years ago

Here is what my current session looks like with the suggested knit_print.sessionInfo function (since it outputs markdown, I just pasted it here; the actual output is what the raw text below looks like):

yihui commented 7 years ago

I think a complete hash is probably too long. Perhaps we can use the first few characters like what devtools::session_info() does.

The other problem is that this function only covers the case for Markdown output. I'm not sure if it is worth supporting other types of output like LaTeX.

billdenney commented 7 years ago

Do you know of a good function to generically print out lists as markdown bulleted lists?

yihui commented 7 years ago

Nope... but as a lazy fallback method, you could simply remove asis_output() when !knitr:::out_format('markdown'), and the output will be printed as verbatim text. But... the problem with that is when the output format is LaTeX, there is no line-wrapping in verbatim environments by default. So perhaps for the case knitr:::out_format('latex'), you just write a helper function to output a list, which is not hard anyway. Note you will need to escape special characters, and there is a helper function knitr:::escape_latex().

billdenney commented 7 years ago

Related to the above, what do you think about this gist (https://gist.github.com/billdenney/5ef10d82e6bcdbcac4f0f38562c23b53) as a way to generate nested lists in markdown? If you like it, would you prefer it here in printr or in the main knitr package (ala kable)?

With that, I can make knit_print.sessionInfo pretty simple and it should work for any of html, LaTeX, and txt (aka markdown) output.

yihui commented 7 years ago

Thanks for the work. Unfortunately I don't have time to review it at the moment, or even in the next couple of months. If you really want this feature, you can use the old good source() in your document and define a function knit_print.sessionInfo (you don't need to declare the S3 method after you have library(knitr)). Eventually I may merge your work, but not right now.