Skip to content
Prev 350929 / 398502 Next

Deparse substitute assign with list elements

You could use a 'replacement function' named 'bar<-', whose last argument
is called 'value', and use bar(variable) <- newValue where you currently
use foo(variable, newValue).

bar <- function(x) {
    x + 3
}
`bar<-` <- function(x, value) {
    bar(value)
}

a <- NA
bar(a) <- 4
a
# [1] 7
b <- list(NA, NA)
bar(b[[1]]) <- 4
b
#[[1]]
#[1] 7
#
#[[2]]
#[1] NA


Bill Dunlap
TIBCO Software
wdunlap tibco.com
On Thu, May 14, 2015 at 11:28 AM, <soeren.vogel at posteo.ch> wrote: