Dropping an element form a list via conventional means (for example ll["name"] <- NULL
), causes the entire list to be copied over. Normally, this is not noticable, until of course the data sets become large.
I have a list with a dozen elements each between 0.25 ~ 2 GB in size. Dropping three elements from this list takes about ten minutes to execute (on a relatively fast machine.)
Is there a way to drop elements from a list in-place?
I have tried the following:
TEST <- list(A=1:20, B=1:5)
TEST[["B"]] <- NULL
TEST["B"] <- NULL
TEST <- TEST[c(TRUE, FALSE)]
data.table::set(TEST, "B", value=NULL) # ERROR
Output with memory info:
cat("\n\n\nATTEMPT 1\n")
TEST <- list(A=1:20, B=1:5)
.Internal(inspect(TEST))
TEST[["B"]] <- NULL
.Internal(inspect(TEST))
cat("\n\n\nATTEMPT 2\n")
TEST <- list(A=1:20, B=1:5)
.Internal(inspect(TEST))
TEST["B"] <- NULL
.Internal(inspect(TEST))
cat("\n\n\nATTEMPT 3\n")
TEST <- list(A=1:20, B=1:5)
.Internal(inspect(TEST))
TEST <- TEST[c(TRUE, FALSE)]