Displaying 1 result from an estimated 1 matches for "recursionfun".
2005 Feb 28
2
Changing function arguments to NULL
...arguments, change some of the arguments and recursively call the same
(or different) function.
For example here's a stupid recursive counting function that prints back
all integers from x to 0 (and ignores arguments y and z)
cnt <- function(x, y, z) {
stopifnot(is.numeric(x))
print (x)
recursionFUN <- match.call()
recursionFUN$x <- x - 1
if (x <= 0) {
invisible(TRUE)
} else {
eval(recursionFUN)
}
}
My problem is that sometimes I want to set one of the arguments to NULL.
But trying to set one of the match.call() arguments to NULL causes it to
be ignored (since the match.call(...