Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increase the width of matrix printout

Tags:

r

When loading a matrix consisting of 12 columns into R, and then printing it, the terminal window in OS X cuts the matrix in half, sort to speak, first showing all the rows with the initial 7 columns and then showing all the rows again with the remaining 5 columns. However, I would like it to display ll the columns, rather than dividing it up. How can I accomplish this?

like image 411
Speldosa Avatar asked Nov 22 '11 12:11

Speldosa


1 Answers

Andrie's answer is good, though sometimes one uses a super duper monitor and 9999 is not enough. ;-)

Here's my function for setting the display width:

setWidth <- function (width = NULL) 
{
    if (is.null(width)) {
        columns <- as.numeric(Sys.getenv("COLUMNS"))   
        if (!is.na(columns)) {
            options(width = columns)
        }
        else {
            options(width = 100)
        }
    }
    else {
        options(width = width)
    }
}

This has been addressed previously, though.

So, to improve on just the changing of width, another trick that I recommend: change the number of digits used in numeric output - set options(digits = ...) to a smaller value. See ?options for more info.

like image 69
Iterator Avatar answered Nov 12 '22 12:11

Iterator