diff --git a/NEWS.md b/NEWS.md index bfe423e2e..f23859487 100644 --- a/NEWS.md +++ b/NEWS.md @@ -126,6 +126,8 @@ 2. data.table is now translated into Brazilian Portuguese (`pt_BR`) as well as Mandarin (`zh_CN`). Thanks to the [new translation team](https://github.com/orgs/Rdatatable/teams/brazil) consisting initially of @rffontenelle, @leofontenelle, and @italo-07. The team is open if you'd also like to join and support maintenance of these translations. +3. A more helpful error message for using `:=` inside the first argument (`i`) of `[.data.table` is now available in translation, [#6293](https://github.com/Rdatatable/data.table/issues/6293). Previously, the code to display this assumed an earlier message was printed in English. The solution is for calling `:=` directly (i.e., outside the second argument `j` of `[.data.table`) to throw an error of class `dt_invalid_let_error`. Thanks to Spanish translator @rikivillalba for spotting the issue and @MichaelChirico for the fix. + # data.table [v1.15.4](https://github.com/Rdatatable/data.table/milestone/33) (27 March 2024) ## BUG FIXES diff --git a/R/data.table.R b/R/data.table.R index 3b27b8d7c..3f8ea8a1e 100644 --- a/R/data.table.R +++ b/R/data.table.R @@ -392,13 +392,11 @@ replace_dot_alias = function(e) { } else if (!is.name(isub)) { ienv = new.env(parent=parent.frame()) - if (getOption("datatable.optimize")>=1L) assign("order", forder, ienv) - i = tryCatch(eval(.massagei(isub), x, ienv), error=function(e) { - if (grepl(":=.*defined for use in j.*only", e$message)) - stopf("Operator := detected in i, the first argument inside DT[...], but is only valid in the second argument, j. Most often, this happens when forgetting the first comma (e.g. DT[newvar := 5] instead of DT[ , new_var := 5]). Please double-check the syntax. Run traceback(), and debugger() to get a line number.") - else - .checkTypos(e, names_x) - }) + if (getOption("datatable.optimize") >= 1L) assign("order", forder, ienv) + i = tryCatch(eval(.massagei(isub), x, ienv), + dt_invalid_let_error = function(e) stopf("Operator := detected in i, the first argument inside DT[...], but is only valid in the second argument, j. Most often, this happens when forgetting the first comma (e.g. DT[newvar := 5] instead of DT[ , new_var := 5]). Please double-check the syntax. Run traceback(), and debugger() to get a line number."), + error = function(e) .checkTypos(e, names_x) + ) } else { # isub is a single symbol name such as B in DT[B] i = try(eval(isub, parent.frame(), parent.frame()), silent=TRUE) @@ -2772,7 +2770,7 @@ address = function(x) .Call(Caddress, eval(substitute(x), parent.frame())) ":=" = function(...) { # this error is detected when eval'ing isub and replaced with a more helpful one when using := in i due to forgetting a comma, #4227 - stopf('Check that is.data.table(DT) == TRUE. Otherwise, :=, `:=`(...) and let(...) are defined for use in j, once only and in particular ways. See help(":=").') + stopf('Check that is.data.table(DT) == TRUE. Otherwise, :=, `:=`(...) and let(...) are defined for use in j, once only and in particular ways. See help(":=").', class="dt_invalid_let_error") } # TODO(#6197): Export these.