Post #3266143
2026-04-07 11:30 UTC
Puzzle: how many copies does x$a[1] <- 99L trigger on a data.frame? TWO. One value changed, two full copies made. A data.frame is a list of column vectors. The list and each column are separate objects with separate reference counts. Modify one column and R copies the column AND the container. What felt like O(1) is O(n). Put that inside a loop. 500MB frame, 100 iterations — 50GB of silent temporary allocations. 1/2
Replies (1)
-
@GillesColling@fosstodon.org 2026-04-07 11:30
Fix: data.table::set() modifies in place, or vectorize so the modification lands in one shot. #rstats 2/2