Scarabee
Scarabee

Reputation: 5704

What are "large vectors" in RStudio?

Using RStudio:

a <- rep(1, 1e4)
b <- rep(1, 1e5)

In the environment pane, a and b are displayed differently:

enter image description here

What's the meaning of Large numeric? I used to think that it meant that b was handled in a special way by R, but using str I can't see anything special. I also read about long vectors, but it seems it's only about vectors with length >= 2^31.

Is it a purely informative comment added by RStudio to notify the user that an object's memory size is bigger than an arbitrary limit?

Upvotes: 5

Views: 466

Answers (1)

Chris
Chris

Reputation: 6372

This looks like a qualifier for objects larger than a half MB. See line 460 here.

  # for large objects (> half MB), don't try to get the value, just show
  # the size. Some functions (e.g. str()) can cause the object to be
  # copied, which is slow for large objects.
  if (size > 524288)
  {
     len_desc <- if (len > 1) 
               paste(len, " elements, ", sep="")
            else 
               ""
     # data frames are likely to be large, but a summary is still helpful
     if (is.data.frame(obj))
     {
        val <- "NO_VALUE"
        desc <- .rs.valueDescription(obj)
     }
     else
     {
        val <- paste("Large ", class, " (", len_desc, 
                     capture.output(print(size, units="auto")), ")", sep="")
     }
     contents_deferred <- TRUE
  }

As per the comment, this prevents a later str() call from copying the object, improving performance for large objects.

The paste("Large", ...) call creates the modified description.

On my computer, this can be demonstrated here:

small <- 1:131050
large <- 1:132000

object.size(small)
# 524240 bytes
object.size(large)
# 528040 bytes

Upvotes: 3

Related Questions