Skip to content

Commit

Permalink
Merge pull request #526 from wch/print-sessioninfo
Browse files Browse the repository at this point in the history
Add session_info function
  • Loading branch information
hadley committed Aug 13, 2014
2 parents 2180831 + fb88f92 commit b98d070
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export(revdep)
export(revdep_check)
export(revdep_maintainers)
export(run_examples)
export(session_info)
export(set_path)
export(show_news)
export(source_gist)
Expand Down
48 changes: 48 additions & 0 deletions R/session-info.r
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,51 @@ dev_packages <- function() {

names(packages)[packages]
}

#' Print session information
#'
#' This function prints out the same information as
#' \code{\link[utils]{sessionInfo}()}, with one difference: it also prints out
#' the GithubSHA1 value of loaded packages, if present.
#'
#' @export
session_info <- function() {

# This is a modified version of utils:::print.sessionInfo from R 3.1.1. It's
# exactly the same except that it also prints out a package's GithubSHA1
# value, if present.
print_session_info <- function (x, locale = TRUE, ...) {
mkLabel <- function(L, n) {
vers <- sapply(L[[n]], function(x) {
str <- x[["Version"]]
if (!is.null(x$GithubSHA1)) {
str <- paste0(str, "(", substr(x$GithubSHA1, 1, 7), ")")
}
str
})
pkg <- sapply(L[[n]], function(x) x[["Package"]])
paste(pkg, vers, sep = "_")
}
cat(x$R.version$version.string, "\n", sep = "")
cat("Platform: ", x$platform, "\n\n", sep = "")
if (locale) {
cat("locale:\n")
print(strsplit(x$locale, ";", fixed = TRUE)[[1]], quote = FALSE,
...)
cat("\n")
}
cat("attached base packages:\n")
print(x$basePkgs, quote = FALSE, ...)
if (!is.null(x$otherPkgs)) {
cat("\nother attached packages:\n")
print(mkLabel(x, "otherPkgs"), quote = FALSE, ...)
}
if (!is.null(x$loadedOnly)) {
cat("\nloaded via a namespace (and not attached):\n")
print(mkLabel(x, "loadedOnly"), quote = FALSE, ...)
}
invisible(x)
}

print_session_info(sessionInfo())
}
13 changes: 13 additions & 0 deletions man/session_info.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
% Generated by roxygen2 (4.0.1): do not edit by hand
\name{session_info}
\alias{session_info}
\title{Print session information}
\usage{
session_info()
}
\description{
This function prints out the same information as
\code{\link[utils]{sessionInfo}()}, with one difference: it also prints out
the GithubSHA1 value of loaded packages, if present.
}

0 comments on commit b98d070

Please sign in to comment.