Skip to content

Commit 7cab6f1

Browse files
Updated warning for referencing a non-existent value during creation of new column (#6016)
* Updated warning message in assign.c, as well as updated tests 316, 944.1 and 944.3 * added spaces for consistency * Update src/assign.c warning Co-authored-by: Michael Chirico <[email protected]> * updated tests --------- Co-authored-by: Michael Chirico <[email protected]>
1 parent 3eefbca commit 7cab6f1

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

inst/tests/tests.Rraw

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ test(313, DT[,a:=1:3], data.table(a=1:3)) # test changed in 1.12.2; can now a
10121012
DT = data.table(a=20:22)
10131013
test(314, {DT[,b:=23:25];DT[,c:=26:28]}, data.table(a=20:22,b=23:25,c=26:28)) # add in series
10141014
test(315, DT[,c:=NULL], data.table(a=20:22,b=23:25)) # delete last
1015-
test(316, DT[,c:=NULL], data.table(a=20:22,b=23:25), warning="Column 'c' does not exist to remove")
1015+
test(316, DT[,c:=NULL], data.table(a=20:22,b=23:25), warning="Tried to assign NULL to column 'c', but this column does not exist to remove")
10161016

10171017
# Test adding, removing and updating columns via [<- in one step
10181018
DT = data.table(a=1:6,b=1:6,c=1:6)
@@ -2809,9 +2809,9 @@ test(943, merge(X,Y,all.y=TRUE,by="a"), data.table(a=2:4,b=INT(5:6,NA),"d 1"=5:7
28092809

28102810
# Test error message about NULL type
28112811
DT = data.table(NULL)
2812-
test(944.1, DT[, foo:=NULL], DT, warning="Column 'foo' does not exist to remove")
2812+
test(944.1, DT[, foo:=NULL], DT, warning="Tried to assign NULL to column 'foo', but this column does not exist to remove")
28132813
test(944.2, DT[,a:=1L], data.table(a=1L)) # can now add columns to an empty data.table from v1.12.2
2814-
test(944.3, DT[,aa:=NULL], data.table(a=1L), warning="Column 'aa' does not exist to remove")
2814+
test(944.3, DT[,aa:=NULL], data.table(a=1L), warning="Tried to assign NULL to column 'aa', but this column does not exist to remove")
28152815
test(944.4, DT[,a:=NULL], data.table(NULL))
28162816
if (base::getRversion() >= "3.4.0") {
28172817
test(944.5, typeof(structure(NULL, class=c("data.table","data.frame"))), 'list', warning="deprecated, as NULL cannot have attributes") # R warns which is good and we like

src/assign.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ SEXP assign(SEXP dt, SEXP rows, SEXP cols, SEXP newcolnames, SEXP values)
430430
if (newcolnum<0 || newcolnum>=length(newcolnames))
431431
error(_("Internal error in assign.c: length(newcolnames)=%d, length(names)=%d, coln=%d"), length(newcolnames), length(names), coln); // # nocov
432432
if (isNull(thisvalue)) {
433-
warning(_("Column '%s' does not exist to remove"),CHAR(STRING_ELT(newcolnames,newcolnum)));
433+
warning(_("Tried to assign NULL to column '%s', but this column does not exist to remove"), CHAR(STRING_ELT(newcolnames,newcolnum)));
434434
continue;
435435
}
436436
// RHS of assignment to new column is zero length but we'll use its type to create all-NA column of that type

0 commit comments

Comments
 (0)