Looks like you're out of luck. From the help file:
‘assign’ does not dispatch assignment methods, so it cannot be used to
set elements of vectors, names, attributes, etc.
Note that assignment to an attached list or data frame changes the
attached copy and not the original object: see ‘attach’ and ‘with’.
If you're passing names(x)
as input, couldn't you use:
nms <- names(x)
for ( n in nms )
x[[n]] <- 'new_value'
Also, are you intending for your function to modify some global variable? e.g.:
x <- list(test=1)
f <- function(...)
x$test <- 2
f() # want x$test = 2 ??
Because this won't work (scope problems). You can make it work with a bit of footwork (<<-
), but this is generally considered bad practice as it's easy to intrtoduce unintentional bugs into your code.
If you could give an example of why you want this function/what purpose it will serve, we could help you find an alternative solution.