From rowe at muxspace.com  Wed Jul 17 17:12:53 2013
From: rowe at muxspace.com (Brian Rowe)
Date: Wed, 17 Jul 2013 11:12:53 -0400
Subject: [Rd] On the mechanics of function evaluation and argument
	matching
In-Reply-To: <CAAmySGOCr5ieKer23OS6hYsyRbKY_WmY-3aK7_N5sBaehwzzNQ@mail.gmail.com>
References: <3727EA1A-F2BE-4C1D-9CBB-2BA6F8ED76A7@muxspace.com>
	<CAAmySGOCr5ieKer23OS6hYsyRbKY_WmY-3aK7_N5sBaehwzzNQ@mail.gmail.com>
Message-ID: <5CC4DF09-7D40-4A0D-BCA4-75C2CEF7E82A@muxspace.com>

Thanks for the lead. Given the example in ?missing though, wouldn't it be safer to explicitly define a default value of NULL:

myplot <- function(x, y=NULL) {
  if(is.null(y)) {
    y <- x
    x <- 1:length(y)
  }
  plot(x, y)
}



On Jul 17, 2013, at 11:05 AM, "R. Michael Weylandt" <michael.weylandt at gmail.com> wrote:

> On Wed, Jul 17, 2013 at 9:58 AM, Brian Rowe <rowe at muxspace.com> wrote:
>> Hello,
>> 
>> Section 4.3.2 of the R language definition [1] states that argument matching to formal arguments is a 3-pass process to match arguments to a function. An error is generated if any (supplied) arguments are left unmatched. Interestingly the opposite is not true as any unmatched formals does not generate an error.
>> 
>>> f <- function(x,y,z) x
>>> f(2)
>> [1] 2
>>> f(2,3)
>> [1] 2
>> 
>> Since R is lazily evaluated, I understand that it is not an error for an unused argument to be unassigned. However, it is surprising to me that a function need not be called with all its required arguments. I guess in this situation technically "required arguments" means required and referenced arguments.
>> 
>>> f()
>> Error in f() : argument "x" is missing, with no default
>> 
>> Can anyone shed light on the reasoning for this design choice?
> 
> I'm not sure I can, but I'd look around at how the missing() function is used.
> 
> Cheers,
> MW



[Rd] On the mechanics of function evaluation and argument matching
Brian Rowe