From h.wickham at gmail.com  Mon Feb 18 19:31:59 2013
From: h.wickham at gmail.com (Hadley Wickham)
Date: Mon, 18 Feb 2013 12:31:59 -0600
Subject: [Rd] quote() vs quote(expr=)
In-Reply-To: <6860B4BC-FCA9-4A93-8817-8BB99AEA1A0D@gmail.com>
References: <CABdHhvGwS1xuOqYLqtJAGjJrm5gGvLW7XJs+4bg3LY_R3Z7oNQ@mail.gmail.com>
	<01CE77E8-6F40-4050-A365-A21DFF933585@gmail.com>
	<CABdHhvHQ8uEqZ7AEhhY131=BRaUXByspdoQuc2+c3=gcBfPARw@mail.gmail.com>
	<6860B4BC-FCA9-4A93-8817-8BB99AEA1A0D@gmail.com>
Message-ID: <CABdHhvG3Z957-JnuiEkFw6D=o=LuAts2oEvXGE2HZ0kWmYvbAw@mail.gmail.com>

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/



[Rd] quote() vs quote(expr=)
Hadley Wickham