[Rd] quote() vs quote(expr=)
Hadley Wickham
h.wickham at gmail.com
Mon Feb 18 19:31:59 CET 2013
On Mon, Feb 18, 2013 at 10:35 AM, peter dalgaard <pdalgd at gmail.com> wrote:
>
> On Feb 18, 2013, at 17:04 , Hadley Wickham wrote:
>
>> quote(expr =) returning missing seems like the right thing to me,
>> quote() throwing an error does not, because it violates the usual
>> semantics where f(x = ) is equivalent to f().
>
> Except that it isn't:
>
>> (function(...)nargs())()
> [1] 0
>> (function(...)nargs())(x=)
> [1] 1
But hardly any functions use nargs:
> find_funs("package:base", fun_calls, fixed("nargs"))
Using environment package:base
[1] "-.Date" "-.POSIXt" "[.data.frame"
[4] "[[.data.frame" "[[<-.data.frame" "[[<-.numeric_version"
[7] "[<-.data.frame" "+.Date" "+.POSIXt"
[10] "diag" "message" "Ops.data.frame"
[13] "Ops.Date" "Ops.difftime" "Ops.numeric_version"
[16] "Ops.POSIXt" "seq.default" "stop"
[19] "system.file" "trace" "warning"
> find_funs("package:stats", fun_calls, fixed("nargs"))
Using environment package:stats
[1] "model.frame.default"
The majority is used to switch between cases like -x vs x - y or to
detect extra arguments if something weird is being done with ...
So I think it's reasonable to expect that f() and f(x = ) do the same thing.
Hadley
--
Chief Scientist, RStudio
http://had.co.nz/
More information about the R-devel
mailing list