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

Add knit_print method for sessionInfo #26

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

billdenney
Copy link

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

yihui commented Feb 7, 2017

Could you show me an output sample? Thanks!

@billdenney
Copy link
Author

billdenney commented Feb 7, 2017

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):

  • R version 3.3.2 (2016-10-31)
  • Platform: x86_64-w64-mingw32/x64 (64-bit)
  • Locale: LC_COLLATE=English_United States.1252, LC_CTYPE=English_United States.1252, LC_MONETARY=English_United States.1252, LC_NUMERIC=C, LC_TIME=English_United States.1252
  • Packages
    • Base: stats, graphics, grDevices, utils, datasets, methods, base
    • Attached: dplyr(0.5.0); cowplot(0.6.2); ggplot2(2.1.0); PKNCA(0.8.0.9005, GithubSHA1: 8b082b7c99319b6b623879b0b67aedad3ad976b1)
    • Namespaces (not attached): Rcpp(0.12.8); lattice(0.20-34); assertthat(0.1); digest(0.6.11); R6(2.1.3); grid(3.3.2); plyr(1.8.4); nlme(3.1-128); gtable(0.2.0); DBI(0.5); magrittr(1.5); scales(0.4.0); lazyeval(0.2.0.9000, GithubSHA1: c155c3d534072ca58bcb5fe22ab185e3e4098c73); labeling(0.3); tools(3.3.2); munsell(0.4.3); parallel(3.3.2); colorspace(1.2-6); knitr(1.15); tibble(1.2)

@yihui
Copy link
Owner

yihui commented Feb 7, 2017

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

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

@yihui
Copy link
Owner

yihui commented Feb 7, 2017

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

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

yihui commented Feb 10, 2017

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.

# Conflicts:
#	DESCRIPTION
#	NAMESPACE
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

Successfully merging this pull request may close these issues.

2 participants