Skip to content

Commit 0be7133

Browse files
Refactored duplicated logic in setDT and [,:=] to use a helper function
1 parent db7b822 commit 0be7133

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

R/data.table.R

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@ is.ff = function(x) inherits(x, "ff") # define this in data.table so that we do
2626
# Used internally for efficient recursive assignments in data.table.
2727

2828
process_assignment <- function(name, x, parent_env) {
29-
k = eval(name[[2L]], parent_env, parent_env)
30-
if (is.list(k)) {
31-
origj = j = if (name[[1L]] == "$") as.character(name[[3L]]) else eval(name[[3L]], parent_env, parent_env)
32-
if (is.character(j)) {
33-
if (length(j) != 1L)
34-
stopf("Cannot assign to an under-allocated recursively indexed list -- L[[i]][,:=] syntax is only valid when i is length 1, but its length is %d", length(j))
35-
j = match(j, names(k))
36-
if (is.na(j))
37-
stopf("Item '%s' not found in names of input list", origj)
38-
}
39-
.Call(Csetlistelt, k, as.integer(j), x)
40-
} else if (is.environment(k) && exists(as.character(name[[3L]]), k)) {
41-
assign(as.character(name[[3L]]), x, k, inherits = FALSE)
42-
}
29+
k = eval(name[[2L]], parent_env, parent_env)
30+
if (is.list(k)) {
31+
origj = j = if (name[[1L]] == "$") as.character(name[[3L]]) else eval(name[[3L]], parent_env, parent_env)
32+
if (is.character(j)) {
33+
if (length(j) != 1L)
34+
stopf("Cannot assign to an under-allocated recursively indexed list -- L[[i]][,:=] syntax is only valid when i is length 1, but its length is %d", length(j))
35+
j = match(j, names(k))
36+
if (is.na(j))
37+
stopf("Item '%s' not found in names of input list", origj)
38+
}
39+
.Call(Csetlistelt, k, as.integer(j), x)
40+
} else if (is.environment(k) && exists(as.character(name[[3L]]), k)) {
41+
assign(as.character(name[[3L]]), x, k, inherits = FALSE)
42+
}
4343
}
4444

4545
#NCOL = function(x) {

0 commit comments

Comments
 (0)