Brian Rowe
2013-Jul-17 14:58 UTC
[Rd] On the mechanics of function evaluation and argument matching
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? Warm Regards, Brian Rowe [1] http://cran.r-project.org/doc/manuals/r-release/R-lang.html#Argument-matching [[alternative HTML version deleted]]
R. Michael Weylandt
2013-Jul-17 15:05 UTC
[Rd] On the mechanics of function evaluation and argument matching
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
Reasonably Related Threads
- actual argument matching does not conform to the definition (PR#13634)
- R CMD Rdconv drops sections: arguments, seealso, examples (PR#9649)
- actual argument matching does not conform to the definition (PR#13635)
- R CMD Rdconv drops sections: arguments, seealso, examples (PR#9645)
- Merge data frame and keep unmatched