@@ -1221,7 +1221,7 @@ replace_dot_alias = function(e) {
12211221 setalloccol(x , n , verbose = verbose ) # always assigns to calling scope; i.e. this scope
12221222 if (is.name(name )) {
12231223 assign(as.character(name ),x ,parent.frame(),inherits = TRUE )
1224- } else if (name % iscall % c( ' $ ' , ' [[ ' ) && is.name( name [[ 2L ]])) {
1224+ } else if (.is_simple_extraction( name )) { # TODO(#6702): use a helper here as the code is very similar to setDT().
12251225 k = eval(name [[2L ]], parent.frame(), parent.frame())
12261226 if (is.list(k )) {
12271227 origj = j = if (name [[1L ]] == " $" ) as.character(name [[3L ]]) else eval(name [[3L ]], parent.frame(), parent.frame())
@@ -1233,6 +1233,8 @@ replace_dot_alias = function(e) {
12331233 .Call(Csetlistelt ,k ,as.integer(j ), x )
12341234 } else if (is.environment(k ) && exists(as.character(name [[3L ]]), k )) {
12351235 assign(as.character(name [[3L ]]), x , k , inherits = FALSE )
1236+ } else if (isS4(k )) {
1237+ .Call(CsetS4elt , k , as.character(name [[3L ]]), x )
12361238 }
12371239 } # TO DO: else if env$<- or list$<-
12381240 }
@@ -2967,7 +2969,7 @@ setDT = function(x, keep.rownames=FALSE, key=NULL, check.names=FALSE) {
29672969 if (is.name(name )) {
29682970 name = as.character(name )
29692971 assign(name , x , parent.frame(), inherits = TRUE )
2970- } else if (name % iscall % c( ' $ ' , ' [[ ' ) && is.name (name [[ 2L ]] )) {
2972+ } else if (.is_simple_extraction (name )) {
29712973 # common case is call from 'lapply()'
29722974 k = eval(name [[2L ]], parent.frame(), parent.frame())
29732975 if (is.list(k )) {
@@ -2979,9 +2981,11 @@ setDT = function(x, keep.rownames=FALSE, key=NULL, check.names=FALSE) {
29792981 stopf(" Item '%s' not found in names of input list" , origj )
29802982 }
29812983 }
2982- .Call(Csetlistelt ,k , as.integer(j ), x )
2984+ .Call(Csetlistelt , k , as.integer(j ), x )
29832985 } else if (is.environment(k ) && exists(as.character(name [[3L ]]), k )) {
29842986 assign(as.character(name [[3L ]]), x , k , inherits = FALSE )
2987+ } else if (isS4(k )) {
2988+ .Call(CsetS4elt , k , as.character(name [[3L ]]), x )
29852989 }
29862990 }
29872991 .Call(CexpandAltRep , x ) # issue#2866 and PR#2882
@@ -3048,6 +3052,9 @@ rleidv = function(x, cols=seq_along(x), prefix=NULL) {
30483052 is.name(e [[1L ]]) && is.name(e [[2L ]]) # e.g. V1:V2, but not min(V1):max(V2) or 1:max(V2)
30493053}
30503054
3055+ # for assignments like x[[1]][, a := 2] or setDT(x@DT)
3056+ .is_simple_extraction = function (e ) e %iscall % c(' $' , ' @' , ' [[' ) && is.name(e [[2L ]])
3057+
30513058# GForce functions
30523059# to add a new function to GForce (from the R side -- the easy part!):
30533060# (1) add it to gfuns
0 commit comments