Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify error for := under with=FALSE #6834

Open
wants to merge 1 commit into
base: depr-inplace
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions R/data.table.R
Original file line number Diff line number Diff line change
Expand Up @@ -686,10 +686,7 @@
if (is.null(jsub)) return(NULL)

if (!with) {
if (jsub %iscall% ":=") {
# TODO(>=1.18.0): Simplify this error
stopf("with=FALSE together with := was deprecated in v1.9.4 released Oct 2014; this has been warning since v1.15.0. Please wrap the LHS of := with parentheses; e.g., DT[,(myVar):=sum(b),by=a] to assign to column name(s) held in variable myVar. See ?':=' for other examples.")
}
if (jsub %iscall% ":=") stopf("`:=` is only supported under with=TRUE.")
Copy link
Member

@ben-schwen ben-schwen Mar 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe keep the

See ?':=' for other examples."

although a bit superfluous?

# missingby was already checked above before dealing with i
if (jsub %iscall% c("!", "-") && length(jsub)==2L) { # length 2 to only match unary, #2109
notj = TRUE
Expand Down Expand Up @@ -1939,7 +1936,7 @@
if (inherits(x, 'data.table')) .Call(C_unlock, x)
else return(lapply(x, runlock, current_depth = current_depth + 1L))
}
return(invisible())

Check warning on line 1939 in R/data.table.R

View workflow job for this annotation

GitHub Actions / lint-r

file=R/data.table.R,line=1939,col=5,[return_linter] Use implicit return behavior; explicit return() is not needed.
}
runlock(ans)
if (verbose) {cat(timetaken(last.started.at),"\n"); flush.console()}
Expand Down Expand Up @@ -3118,7 +3115,7 @@
return(FALSE)
}
# calls are allowed <=> there's no SYMBOLs in the sub-AST
return(length(all.vars(q, max.names=1L, unique=FALSE)) == 0L)

Check warning on line 3118 in R/data.table.R

View workflow job for this annotation

GitHub Actions / lint-r

file=R/data.table.R,line=3118,col=3,[return_linter] Use implicit return behavior; explicit return() is not needed.
}
.gshift_ok = function(q) {
q = match.call(shift, q)
Expand Down Expand Up @@ -3342,7 +3339,7 @@
setkeyv(i, idxCols)
on = on[idxCols] ## make sure 'on' is in the correct order. Otherwise the logic won't recognise that a key / index already exists.
}
return(list(i = i,

Check warning on line 3342 in R/data.table.R

View workflow job for this annotation

GitHub Actions / lint-r

file=R/data.table.R,line=3342,col=3,[return_linter] Use implicit return behavior; explicit return() is not needed.
on = on,
notjoin = notjoin
)
Expand Down
4 changes: 2 additions & 2 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -4629,7 +4629,7 @@ test(1241, DT[order(x,-y)], # optimized to forder()

DT = data.table(a=1:3, b=4:6)
myCol = "a"
test(1242.1, DT[2,myCol:=6L,with=FALSE], error="with=FALSE together with := was deprecated in v1.9.4")
test(1242.1, DT[2,myCol:=6L,with=FALSE], error="`:=` is only supported under with=TRUE.")
test(1242.2, DT[2,(myCol):=7L], data.table(a=INT(1,7,3), b=4:6))

# consistency of output type of mult, #340
Expand Down Expand Up @@ -13926,7 +13926,7 @@ test(1967.42, x[3, rollends = rep(TRUE, 10L)], error = 'rollends must be length
test(1967.43, x[ , ..], error = 'symbol .. is invalid')
test(1967.44, x[NULL], data.table(NULL))
test(1967.45, x[ , NULL], NULL)
test(1967.46, x[ , 'b' := 6:10, with=FALSE], error='with=FALSE together with :=')
test(1967.46, x[ , 'b' := 6:10, with=FALSE], error='`:=` is only supported under with=TRUE.')
x[, b := 6:10]
test(1967.47, x[ , -1L, with = FALSE], data.table(b = 6:10))
test(1967.48, x[ , b, .SDcols = 'a'], 6:10,
Expand Down
Loading