allArgs <- as.list(mc[-1])
allArgs[[arg]] <- curArg + offset
e <- do.call("call", c(as.character(mc[[1]]), allArgs))
}
for (i in 1:length(e)) e[[i]] <- Recall(e[[i]], arg = arg, offset =
offset)
return(e)
}
-Original Message-----
From: Thomas L
On Sun, 22 Oct 2006, McGehee, Robert wrote:
> R-Developers,
> I'm looking for some help computing on the R language.
>
> I'm hoping to write a function that parses a language or expression
> object and returns another expression with all instances of certain
> argument of a given function altered.
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:lengt
See
?body
?parse
?deparse
?gsub
> foo <- function(x) x+.1
> bar <- function(y) y+foo(x=1) + foo(x=2)
> bar(1)
[1] 4.2
> body(bar)
y + foo(x = 1) + foo(x = 2)
> body(bar) <- parse(text=gsub("x[ ]*=[ ]*([0-9])","x = 1 +
> \\1",deparse(body(bar
> bar(1)
[1] 6.2
R-Developers,
I'm looking for some help computing on the R language.
I'm hoping to write a function that parses a language or expression
object and returns another expression with all instances of certain
argument of a given function altered. For instance, say I would like my
function, myFun to ta