How to Increase the limit for max.print in R

Sometimes when doing data science in R studio the number of items you are working with exceeds the maximum number of items that can be printed at one time. This max.print paramete has the value of a thousand so in most cases, it is not likely to be a problem. However, sometimes you may have a really big job that exceeds this limit. when this is the case you are going to want to increase the max.print limit.

Using the Options Function To Adjust max.print

If you need to increase the limit for the max.print parameter in R programming, you use the options function. Ironically this function can also be used to decrease it, but you are unlikely ever to have to decrease the size of this parameter. The options function has the format of options(option = value) and sets the option to the value. When it is used to set the max.print parameter the format is options(max.print = value) and it sets the max.print parameter to the provided numeric value. You can check the current value of this parameter using the getOption function. Using this function in a program provides a way of checking the value of this parameter, to compare it against the number of items needed for your output. The default value of the max.print parameter is one thousand, so you will need to increase it, if you have more than one thousand items to output.

How max.print works (and why it is there)

The reason why the max.print parameter exists and is limited to one-thousand-line items is that on many systems the R studio environment tends to slow down a lot if the content gets too big. The reason for this slowdown is that the system is taking up too much memory. Whenever a computer runs short on internal memory it will often tap its hard drive. The problem is that a hard drive is slower than internal memory and so it slows down the system’s operation. Now, the advent of solid-state drives replacing disk-based hard drives reduces this problem because solid-state drives are a lot faster than hard drives. Because of this, it is safe when using a computer that has a solid-state drive to extend the size of the max.print parameter. As a result, if the situation calls for it, being able to extend the size of the max.print parameter could be helpful when writing a long program.

Three Code Examples of fixing max.print

Here we have three examples however of increasing the size of the max.print parameter. Each of them sets it to a different value.

> A = getOption(“max.print”)
> A
[1] 1000
> options(max.print = 10000)
> getOption(“max.print”)
[1] 10000

This example sets the size of the max.print parameter to ten thousand, this increases its size by a factor of ten.

> A = getOption(“max.print”)
> A
[1] 1000
> options(max.print = 100000)
> getOption(“max.print”)
[1] 100000

This example sets the size of the max.print parameter to one hundred thousand, this increases its size by a hundred times.

> A = getOption(“max.print”)
> A
[1] 1000
> options(max.print = 999999)
> getOption(“max.print”)
[1] 999999

This example sets the size of the max.print parameter to almost a million, this increases its size by a thousand times.

When To Use This Solution

The main application of applying the options function to the max.print parameter is working with large programs and large amounts of data. If you are writing a program that is going to be over a thousand lines, then you are going to want to increase this parameter so that you do not have any problems with your output. Given the ways that R programming is generally used it is highly unlikely that you are going to be writing a program that is this long, but it could happen. The more likely situation is working with a large amount of data, where you are going to have over a thousand lines of data. Such a large data set is unusual but sometimes necessary to be statistically meaningful. In this case, you also want to increase the size of this parameter.

Changing the size of the max.print parameter is necessary when dealing with either large amounts of data or a large program. In either case, increasing the size of this parameter is a useful tool to have in your toolbox, if you need it.

Scroll to top
Privacy Policy