Skip to content

Commit 7ee7f86

Browse files
committed
updated logic
1 parent 4e1827d commit 7ee7f86

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

R/data.table.R

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,16 @@ replace_dot_alias = function(e) {
128128
}
129129
}
130130

131-
.assign_in_parent = function(name, value, env, err_msg_len, err_msg_na) {
131+
.assign_in_parent = function(name, value, env, err_msg_detail, err_msg_na) {
132132
k = eval(name[[2L]], env, env)
133133
if (is.list(k)) {
134134
origj = j = if (name[[1L]] == "$") as.character(name[[3L]]) else eval(name[[3L]], env, env)
135135
if (length(j) != 1L) {
136-
stopf(err_msg_len, length(j))
136+
stopf(
137+
"Cannot assign with a recursive index of length %d. The syntax %s is only valid when the index is length 1.",
138+
length(j),
139+
err_msg_detail
140+
)
137141
}
138142
if (is.character(j)) {
139143
idx = match(j, names(k))
@@ -1243,8 +1247,8 @@ replace_dot_alias = function(e) {
12431247
} else if (.is_simple_extraction(name)) {
12441248
.assign_in_parent(
12451249
name, x, parent.frame(),
1246-
err_msg_len = "The index for recursive assignment must be length 1, but its length is %d.",
1247-
err_msg_na = NULL # Triggers internal_error for this case
1250+
err_msg_detail = "L[[i]][,:=]",
1251+
err_msg_na = NULL # Triggers internal_error
12481252
)
12491253
} # TO DO: else if env$<- or list$<-
12501254
}
@@ -2992,8 +2996,8 @@ setDT = function(x, keep.rownames=FALSE, key=NULL, check.names=FALSE) {
29922996
# common case is call from 'lapply()'
29932997
.assign_in_parent(
29942998
name, x, parent.frame(),
2995-
err_msg_len = "The index for recursive assignment must be length 1, but its length is %d.",
2996-
err_msg_na = "Item '%s' not found in names of input list"
2999+
err_msg_detail = "setDT(L[[i]])",
3000+
err_msg_na = "Item '%s' not found in names of input list"
29973001
)
29983002
} else if (name %iscall% "get") { # #6725
29993003
# edit 'get(nm, env)' call to be 'assign(nm, x, envir=env)'

inst/tests/tests.Rraw

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15880,7 +15880,7 @@ test(2074.03, data.table(grade=c(50L, 91L, 95L, 51L, 89L))[ , .N, by=evaluate(gr
1588015880
## error: use recursive character list indexing to assign when also doing alloc.col()
1588115881
opt = options(datatable.alloccol=1L)
1588215882
l = list(foo = list(bar = data.table(a = 1:3, b = 4:6)))
15883-
test(2074.04, l[[c('foo', 'bar')]][ , (letters) := 16:18], error = 'The index for recursive assignment must be length 1')
15883+
test(2074.04, l[[c('foo', 'bar')]][ , (letters) := 16:18], error = 'Cannot assign with a recursive index of length')
1588415884
options(opt)
1588515885
## alloc.col when using 0-truelength j assigning to a subset
1588615886
DT = data.table(a=1)
@@ -21172,4 +21172,4 @@ test(2317.9, DT1[DF2, on='a', .(e = x.a + i.e)]$e, 6)
2117221172
test(2318.1, {
2117321173
data_store = list(nested = list(df_to_fix = data.frame(id = 1:3, val = letters[1:3])))
2117421174
setDT(data_store[[c("nested", "df_to_fix")]])
21175-
}, error = "index for recursive assignment must be length 1")
21175+
}, error = "Cannot assign with a recursive index of length")

0 commit comments

Comments
 (0)