The title is the self-contained question. An example clarifies it: Consider
x=list(a=1, b="name")
f <- function(){
assign('y[["d"]]', FALSE, parent.frame() )
}
g <- function(y) {f(); print(y)}
g(x)
$a
[1] 1
$b
[1] "name"
whereas I would like to get
g(x)
$a
[1] 1
$b
[1] "name"
$d
[1] FALSE
A few remarks. I knew what is wrong in my original example, but am using it to make clear my objective. I want to avoid <<-, and want x to be changed in the parent frame.
I think my understanding of environments is primitive, and any references are appreciated.
The first argument to
assignmust be a variable name, not the character representation of an expression. Try replacingfwith:Note that
a,banddare list components, not list attributes. If we wanted to add an attribute"d"toyinf‘s parent frame we would do this:Also, note that depending on what you want to do it may (or may not) be better to have
xbe an environment or a proto object (from the proto package).