Skip to content

Commit 309d84a

Browse files
committed
updated error message
1 parent 8f5ffa8 commit 309d84a

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

R/data.table.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ replace_dot_alias = function(e) {
312312
root = root_name(jsub)
313313
} else if (length(jsub) > 2L && jsub[[2L]] %iscall% ":=") {
314314
#2142 -- j can be {} and have length 1
315-
stopf("You have wrapped := with {} which is ok but then := must be the only thing inside {}. You have something else inside {} as well. Consider placing the {} on the RHS of := instead; e.g. DT[,someCol:={tmpVar1<-...;tmpVar2<-...;tmpVar1*tmpVar2}]")
315+
stopf("You have wrapped `:=` with `{}` which is ok, but then `:=` must be the only thing inside `{}` and must be used only once. You have other statements inside the `{}`. Consider placing `{}` on the RHS of `:=` instead, e.g., DT[, someCol := { tmpVar <- ...; tmpVar*2 }].")
316316
}
317317
}
318318
if (root=="eval" && !any(all.vars(jsub[[2L]]) %chin% names_x)) {
@@ -2880,7 +2880,7 @@ address = function(x) .Call(Caddress, eval(substitute(x), parent.frame()))
28802880

28812881
":=" = function(...) {
28822882
# 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
2883-
stopf('Check that is.data.table(DT) == TRUE. Otherwise, :=, `:=`(...) and let(...) are defined for use in j, once only and in particular ways. Note that namespace-qualification like data.table::`:=`(...) is not supported. See help(":=").', class="dt_invalid_let_error")
2883+
stopf('Check that is.data.table(DT) == TRUE. Otherwise, `:=` is defined for use in j, once only and in particular ways. See help(":="). A common reason for this error is allocating a new column in `j` and using `<-` instead of `:=`; e.g., `DT[, new_col <- 1]` should be `DT[, new_col := 1]`. Another is using `:=` in a multi-statement `{...}` block; please use `:=` as the only statement in `j`.', class="dt_invalid_let_error")
28842884
}
28852885

28862886
# TODO(#6197): Export these.

man/assign.Rd

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
\description{
77
Fast add, remove and update subsets of columns, by reference. \code{:=} operator can be used in two ways: \code{LHS := RHS} form, and \code{Functional form}. See \code{Usage}.
88

9+
Note that when using \code{:=} inside a \code{{...}} block in \code{j}, the \code{:=} call must be the only statement. For assigning to multiple columns, use the functional form: \code{DT[, `:=`(col1=val1, col2=val2)]}.
10+
911
\code{set} is a low-overhead loop-able version of \code{:=}. It is particularly useful for repetitively updating rows of certain columns by reference (using a for-loop). See \code{Examples}. It can not perform grouping operations.
1012

1113
\code{let} is an alias for the functional form and behaves exactly like \code{`:=`}.
@@ -66,7 +68,8 @@ All of the following result in a friendly error (by design) :
6668
x := 1L
6769
DT[i, col] := val
6870
DT[i]$col := val
69-
DT[, {col1 := 1L; col2 := 2L}] # Use the functional form, `:=`(), instead (see above).
71+
DT[, {col1 := 1L; col2 := 2L}] # Using `{}` in `j` is reserved for single `:=` expressions.
72+
# For multiple updates, use the functional form `:=`() instead.
7073
}
7174

7275
For additional resources, please read \href{../doc/datatable-faq.html}{\code{vignette("datatable-faq")}}. Also have a look at StackOverflow's \href{https://stackoverflow.com/questions/tagged/data.table/}{data.table tag}.

0 commit comments

Comments
 (0)