Home > OS >  Under what conditions does the "large list" moniker appear in RStudio?
Under what conditions does the "large list" moniker appear in RStudio?

Time:10-19

While working with lists, I realized that a list I was working with has a description of Large list (113 elements, 4.8 MB).

Weirdly, after adding a column to each of the dataframes in the first list, the resulting list is simply described as List of 113 even though the memory size should be larger.

Here is a screen capture of the two lists' description in the environment.

enter image description here

list2 has one more column in each of the 113 dataframes than list1.

The fact that the size of list2 being larger than list1 is also confirmed.

> object.size(list1)
4760400 bytes
> object.size(list2)
5023240 bytes

What are the conditions for R Studio to describe a list as a "[large] list"? My guess was a list over a certain size, but the example above disproves that.

CodePudding user response:

The string that describes the object in the environment pane is obtained internally by the function .rs.describeObject

If I create a list of data frames which is 5.8MB in size, we can see that this matches the output in the environment panel:

set.seed(1)

list1 <- lapply(1:113, function(x) as.data.frame(replicate(20, rnorm(300))))

enter image description here

We can get the same description string by running the code:

.rs.describeObject(.GlobalEnv, "list1")$value
#> [1] "Large list (113 elements,  5.8 MB)"
#> attr(,"class")
#> [1] "rs.scalar"

Looking at the code of the function, the size above which an object is labelled as "Large" is 524288, i.e. half a megabyte, determined by this line of code:

    if (size > 524288) {

However, this does not explain why your second list does not have the "Large" adjective applied to it. As it happens, I cannot replicate your findings, since if I do:

list2 <- lapply(list1, function(x) {x$a <- rnorm(300); x})

I now have

enter image description here

It seems there are some contexts in which the third argument to .rs.describeObject, which is computeSize may be set to FALSE and cause the object size not to be calculated in the environment pane. Without knowing the code you used to create the "silently large" list2, it's not possible to trace this through.

TL;DR

The bottom line is that most of the time, an object is "Large" if it is greater than half a megabyte, but depending on how the object was created, its size may not be calculated in the environment pane.

  • Related