diff --git a/R/data.table.R b/R/data.table.R index f7b9b4192c..24eff62d58 100644 --- a/R/data.table.R +++ b/R/data.table.R @@ -145,6 +145,10 @@ replace_dot_alias = function(e) { # the drop=NULL is to sink drop argument when dispatching to [.data.frame; using '...' stops test 147 if (!cedta()) { # Fix for #500 (to do) + if (substitute(j) %iscall% c(":=", "let")) { + # Throw a specific error message + stopf("[ was called on a data.table in an environment that is not data.table-aware (i.e. cedta()), but '%s' was used, implying the owner of this call really intended for data.table methods to be called. See vignette('datatable-importing') for details on properly importing data.table.", as.character(substitute(j)[[1L]])) + } Nargs = nargs() - (!missing(drop)) ans = if (Nargs<3L) { `[.data.frame`(x,i) } # drop ignored anyway by DF[i] else if (missing(drop)) `[.data.frame`(x,i,j) diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 2e75c8c96a..24b4f4c60e 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -18419,3 +18419,9 @@ test(2251.10, dim(fread(text, fill=TRUE)), c(9L, 9L)) test(2251.11, dim(fread(text, fill=7)), c(9L, 9L)) test(2251.12, dim(fread(text, fill=9)), c(9L, 9L)) test(2251.13, dim(fread(text, fill=20)), c(9L, 20L)) # clean up currently only kicks in if sep!=' ' + +.datatable.aware = FALSE +dt = data.table(a = 1L) +test(2252.1, dt[, b:=2L], error = "\\[ was called on a data.table.*not data.table-aware.*':='") +test(2252.2, dt[, let(b=2L)], error = "\\[ was called on a data.table.*not data.table-aware.*'let'") +rm(.datatable.aware)