Skip to content

Commit

Permalink
Run setalloccol before _any_ set* affects original table
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelChirico committed Sep 29, 2024
1 parent c83b457 commit 73add71
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions R/data.table.R
Original file line number Diff line number Diff line change
Expand Up @@ -2922,13 +2922,15 @@ setDT = function(x, keep.rownames=FALSE, key=NULL, check.names=FALSE) {
break
}
}
rn = if (!identical(keep.rownames, FALSE)) rownames(x) else NULL
setattr(x, "row.names", .set_row_names(nrow(x)))
if (check.names) setattr(x, "names", make.names(names(x), unique=TRUE))

# setalloccol results in a shallow copy. Must be performed before class setting,
# to have the class apply only to the new copy. #4784
setalloccol(x)

rn = if (!identical(keep.rownames, FALSE)) rownames(x) else NULL
setattr(x, "row.names", .set_row_names(nrow(x)))
if (check.names) setattr(x, "names", make.names(names(x), unique=TRUE))

# fix for #1078 and #1128, see .resetclass() for explanation.
setattr(x, "class", .resetclass(x, 'data.frame'))

Expand Down

0 comments on commit 73add71

Please sign in to comment.