From Robert.McGehee at geodecapital.com  Mon Feb 28 21:58:38 2005
From: Robert.McGehee at geodecapital.com (McGehee, Robert)
Date: Mon Feb 28 21:58:54 2005
Subject: [Rd] Changing function arguments to NULL
Message-ID: <67DCA285A2D7754280D3B8E88EB5480206741E84@MSGBOSCLB2WIN.DMN1.FMR.COM>

I'm trying to build a recursive set of functions that take a set of
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() output is coerced into a list). What
I'd like is that the match.call() output could be converted into an
alist, so that tagged values with no arguments could be handled and
passed on to the next function call without being ignored.

However, I haven't been able to figure out how to construct this alist
without knowing ahead of time what all of the function arguments are and
typing them in explicitly:
e.g. alist(x = 5, y = 2, z = 3).

Re-assigning and then re-evaluating output of the match.call() function
might not be the way to go, but I am not sure, and would appreciate any
comments on the best way to set function arguments to NULL before
evaluating.

Thanks,
Robert

Robert McGehee
Geode Capital Management, LLC
53 State Street, 5th Floor | Boston, MA | 02109
Tel: 617/392-8396    Fax:617/476-6389
mailto:robert.mcgehee@geodecapital.com



This e-mail, and any attachments hereto, are intended for us...{{dropped}}


[Rd] Changing function arguments to NULL
McGehee, Robert