0

I was trying to store the pretty-printed (formatted) output of sessionInfo in a character variable and have found a solution using pretty.si <-capture.output(sessionInfo()) which results in a vector of character strings (one element per line).

Just out of curiosity:

Which function is called by R to get the pretty-printed output (e. g. I couldn't find a S3 print.sessionInfo function)?

If I look into the implementation of sessionInfo it just returns the unformatted result as list of lists or vectors:

> sessionInfo
function (package = NULL) 
{
    z <- list()
    z$R.version <- R.Version()
    z$platform <- z$R.version$platform
    # ... omitted code ...
    class(z) <- "sessionInfo"
    z
}

Edit 1: BTW - To create a pretty-printed string from sessionInfo() you can use:

si <- capture.output(print(sessionInfo()))
R Yoda
  • 8,358
  • 2
  • 50
  • 87

1 Answers1

3

It does actually have an S3 method, it's just not exported from the package namespace which would be the utils package.

If you look through the output of the methods search you will see an asterix next to the sessionInfo method, which the documentation says is:

The S3 method name is followed by an asterisk * if the method definition is not exported from the package namespace in which the method is defined.

> x = methods("print")
> x[x == "print.sessionInfo"]
[1] "print.sessionInfo"

therefore to see the code of the method you can do

utils:::print.sessionInfo
zacdav
  • 4,603
  • 2
  • 16
  • 37