Skip to content
Prev 22516 / 63421 Next

Changing function arguments

Try this.  If the first arg of FUN is x then it increments it.

incrx <- function (e) {
    is.node <- function(x) is.symbol(x) || is.double(x)
    if (is.node(e)) return(e)
    if (is.name(e[[1]]) && e[[1]] == as.name("FUN") && names(e)[2] == "x")
        e[[2]] <- e[[2]] + 1
    for (i in 1:length(e)) e[[i]] <- incrx(e[[i]])
    return(e)
}

incrx(expression(FUN(x = 0) + log(FUN(x = 3))))
On 10/22/06, McGehee, Robert <Robert.McGehee at geodecapital.com> wrote: