How to aviod R warning: reached getOption(“max.print”)

One warning message you may encounter in R is:
[ reached getOption("max.print") -- omitted 502 rows ]

This message appears when you attempt to print more than 1000 values at once in RStudio.

By default, RStudio only lets you print 1000 values at once. However, you can easily increase this limit by using the following method:

  • Method 1: Increase Limit to Specific Value
    #increase print limit to 2000 values
    options(max.print=2000)

The following example shows how to use these methods in practice.

Example: Increase Print Limit in R
Suppose we create a data frame in R with 1,002 rows and 2 columns:

Click for details
#make this example reproducible
set.seed(0)

#create data frame
df <- data.frame(x=runif(1002),
                 y=runif(1002))

#view head of data frame
head(df)
          x          y
1 0.8966972 0.68486090
2 0.2655087 0.38328339
3 0.3721239 0.95498800
4 0.5728534 0.11835658
5 0.9082078 0.03910006
6 0.2016819 0.50450503

Then suppose we attempt to print the entire data frame in RStudio:
df

We’re only able to view the first 500 rows (i.e. the first 1,000 values) and we receive the warning that 502 rows were omitted.

However, if we use the max.print function then we can increase the print limit to 2,500 values:

Click for details
#increase print limit to 2500 values
options(max.print=2500)

#attempt to print entire data frame again
df

This time we’re able to print all 1,002 rows in the data frame and we receive no warning message since we increased the print limit.

source: https://www.statology.org/r-reached-getoption-max-print/

posted @ 2022-06-28 17:08  DaqianLU  阅读(634)  评论(0)    收藏  举报