From rpeng at jhsph.edu  Mon Feb 28 22:58:12 2005
From: rpeng at jhsph.edu (Roger D. Peng)
Date: Mon Feb 28 23:00:27 2005
Subject: [Rd] Changing function arguments to NULL
In-Reply-To: <67DCA285A2D7754280D3B8E88EB5480206741E84@MSGBOSCLB2WIN.DMN1.FMR.COM>
References: <67DCA285A2D7754280D3B8E88EB5480206741E84@MSGBOSCLB2WIN.DMN1.FMR.COM>
Message-ID: <422393F4.9040204@jhsph.edu>

I'm not sure what you're doing but did you try

recursionFUN$x <- list(NULL)

?

-roger

McGehee, Robert wrote:
> 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}}
> 
> ______________________________________________
> R-devel@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>


[Rd] Changing function arguments to NULL
Roger D. Peng