From pd@lgd @ending from gm@il@com  Sun Oct  7 15:05:07 2018
From: pd@lgd @ending from gm@il@com (Peter Dalgaard)
Date: Sun, 7 Oct 2018 15:05:07 +0200
Subject: [Rd] Warning when calling formals() for `[`.
In-Reply-To: <CA+JCgN254QaHVepo03ZuGLsatwmjfDSnUP3yq43N6TguBdWN5g@mail.gmail.com>
References: <CA+JCgN254QaHVepo03ZuGLsatwmjfDSnUP3yq43N6TguBdWN5g@mail.gmail.com>
Message-ID: <634D4A0E-A036-4FEB-8C85-978262B46EA7@gmail.com>

There is more "fun" afoot here, but I don't recall what the point may be:

> args(get("+"))
function (e1, e2) 
NULL
> args(get("["))
NULL
> get("[")
.Primitive("[")
> get("+")
function (e1, e2)  .Primitive("+")

The other index operators, "[[", "[<-", "[[<-" are similar

The docs are pretty clear that args() on a primitive should yield a closure, so at least the documentation seems to be wrong.

-pd


> On 6 Oct 2018, at 19:26 , Laurent Gautier <lgautier at gmail.com> wrote:
> 
> Hi,
> 
> A short code example showing the warning might the only thing needed here:
> 
> ```
>> formals(args(`[`))
> NULL
> 
> *Warning message:In formals(fun) : argument is not a function*
>> is.function(`[`)
> [1] TRUE
>> is.primitive(`[`)
> [1] TRUE
> ```
> 
> Now with an other primitive:
> 
> ```
>> formals(args(`sum`))
> $...
> 
> 
> $na.rm
> [1] FALSE
> 
>> is.function(`sum`)
> [1] TRUE
>> is.primitive(`sum`)
> [1] TRUE
>> class(`[`)
> [1] "function"
> ```
> 
> Is this a feature ?
> 
> 
> Laurent
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



[Rd] Warning when calling formals() for `[`.
Peter Dalgaard