-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Labels
Description
These two regions are close to identical:
Lines 1224 to 1236 in 70c64ac
| } else if (name %iscall% c('$', '[[') && is.name(name[[2L]])) { | |
| k = eval(name[[2L]], parent.frame(), parent.frame()) | |
| if (is.list(k)) { | |
| origj = j = if (name[[1L]] == "$") as.character(name[[3L]]) else eval(name[[3L]], parent.frame(), parent.frame()) | |
| if (is.character(j)) { | |
| if (length(j)!=1L) 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)) | |
| j = match(j, names(k)) | |
| if (is.na(j)) internal_error("item '%s' not found in names of list", origj) # nocov | |
| } | |
| .Call(Csetlistelt,k,as.integer(j), x) | |
| } else if (is.environment(k) && exists(as.character(name[[3L]]), k)) { | |
| assign(as.character(name[[3L]]), x, k, inherits=FALSE) | |
| } |
Lines 2970 to 2985 in 70c64ac
| } else if (name %iscall% c('$', '[[') && is.name(name[[2L]])) { | |
| # common case is call from 'lapply()' | |
| k = eval(name[[2L]], parent.frame(), parent.frame()) | |
| if (is.list(k)) { | |
| origj = j = if (name[[1L]] == "$") as.character(name[[3L]]) else eval(name[[3L]], parent.frame(), parent.frame()) | |
| if (length(j) == 1L) { | |
| if (is.character(j)) { | |
| j = match(j, names(k)) | |
| if (is.na(j)) | |
| stopf("Item '%s' not found in names of input list", origj) | |
| } | |
| } | |
| .Call(Csetlistelt,k,as.integer(j), x) | |
| } else if (is.environment(k) && exists(as.character(name[[3L]]), k)) { | |
| assign(as.character(name[[3L]]), x, k, inherits=FALSE) | |
| } |
To keep them in sync, the logic should be extracted to an appropriate helper.