Skip to content

Commit 6f8020f

Browse files
committed
add assign and tests
1 parent d8513e7 commit 6f8020f

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

R/data.table.R

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2849,12 +2849,11 @@ setcolorder = function(x, neworder=key(x), before=NULL, after=NULL, skip_absent=
28492849
set = function(x,i=NULL,j,value) # low overhead, loopable
28502850
{
28512851
# If removing columns from a table that's not selfrefok, need to call setalloccol first, #7488
2852-
if (is.null(value) || (is.list(value) && any(vapply_1b(value, is.null)))) {
2853-
# Removing at least one column
2854-
ok = selfrefok(x, verbose=FALSE)
2855-
if (ok < 1L) {
2856-
# Table is not safe to resize (either fresh from disk or shallow copy)
2857-
setalloccol(x, n=eval(getOption("datatable.alloccol")), verbose=FALSE)
2852+
if ((is.null(value) || (is.list(value) && any(vapply_1b(value, is.null)))) && selfrefok(x, verbose=FALSE) < 1L) {
2853+
name = substitute(x)
2854+
setalloccol(x, verbose=FALSE)
2855+
if (is.name(name)) {
2856+
assign(as.character(name), x, parent.frame(), inherits=TRUE)
28582857
}
28592858
}
28602859
.Call(Cassign,x,i,j,NULL,value)

inst/tests/tests.Rraw

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21898,8 +21898,14 @@ rm(DT, strings)
2189821898

2189921899
# do remove columns in freshly unserialized data.tables, #7488
2190021900
DT = unserialize(serialize(as.data.table(mtcars), NULL))
21901-
test(2351.1, copy(DT)[,carb:=NULL], as.data.table(mtcars)[,carb:=NULL])
21902-
test(2351.2, set(copy(DT), j="carb", value=NULL), as.data.table(mtcars)[,carb:=NULL])
21901+
test(2351.1, DT[,carb:=NULL], as.data.table(mtcars)[,carb:=NULL])
21902+
DT = unserialize(serialize(as.data.table(mtcars), NULL))
21903+
test(2351.2, set(DT, j="carb", value=NULL), as.data.table(mtcars)[,carb:=NULL])
21904+
DT = unserialize(serialize(as.data.table(mtcars), NULL))
21905+
null_in_value <- NULL
21906+
test(2351.3, "cyl" %notin% names(DT[, cyl := null_in_value]), FALSE)
21907+
DT = unserialize(serialize(as.data.table(mtcars), NULL))
21908+
test(2351.4, ncol(DT[, c("cyl", "mpg") := .(null_in_value, null_in_value)]), ncol(mtcars) - 2)
2190321909
rm(DT)
2190421910

2190521911
# rbindlist did not protect the temporary UTF-8 strings, #7452

0 commit comments

Comments
 (0)