assign The first argument must be the name of the object. Your use of assign basically matches the counter example at the end of the assignment help page. Note:
> x=list(a=1, b="name") > f <- function(){ + assign('x["d"]', FALSE, parent.frame() ) + } > g <- function(y) {f(); print(`x["d"]`)} > g(x) [1] FALSE
This may be the place where you want to use "<<-", but it is usually considered suspicious.
> f <- function(){ + x$d <<- FALSE + } > g <- function(y) {f(); print(y)} > g(x) $a [1] 1 $b [1] "name" $d [1] FALSE
Further thought, proposed in the absence of any purpose for this exercise and ignoring the term โattributesโ that Gabor has indicated, has a definite meaning in R, but it may not have been your goal. If all you need is a result that meets your specifications, then this will achieve this goal, but note that no x changes in the global environment occur.
> f <- function(){ + assign('y', c(x, d=FALSE), parent.frame() ) + } > g <- function(y) {f(); print(y)} > g(x) $a [1] 1 $b [1] "name" $d [1] FALSE > x
The parent frame for f is what can be called the "internal element of g , but the change does not apply to the global environment.
source share