From p.dalgaard@biostat.ku.dk  Fri Mar  3 11:55:21 2000
From: p.dalgaard@biostat.ku.dk (Peter Dalgaard BSA)
Date: 03 Mar 2000 12:55:21 +0100
Subject: [Rd] using function names as parameters (PR#469)
In-Reply-To: hothorn@ci.tuwien.ac.at's message of "Fri, 3 Mar 2000 10:10:59 +0100 (MET)"
References: <200003030910.KAA15280@pubhealth.ku.dk>
Message-ID: <x2og8wi7yu.fsf@blueberry.kubism.ku.dk>

hothorn@ci.tuwien.ac.at writes:

> When using a function name as parameter, here date, the following happends: 
> 
> R> foo <- function(date=date()) cat(date, "\n")
> R> foo()
> Error in cat(date, "\n") : recursive default argument reference

This is not a bug. Default arguments are evaluated in the frame of the
called function, so when the date variable is requested and no actual
argument was supplied, R tries to evaluate the default expression, but
that involved the variable "date" again. If you pass an argument, the
default expression is never evaluated and the problem does not arise.

Similarly a definition like

function(x=y, y=x) x + y

is asking for trouble if both x and y are left unspecified on the call.

[This has nothing to do with passing functions as parameters, by the
way] 
-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


[Rd] using function names as parameters (PR#469)
Peter Dalgaard BSA