Warning when calling formals() for `[`.

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Warning when calling formals() for `[`.

lgautier
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]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Warning when calling formals() for `[`.

Rui Barradas
Hello,

I believe that this is maybe not a *feature* but at least expected
behaviour.

The call formals(args(`[`)) breaks down to


 > args(`[`)
NULL
 > formals(NULL)
NULL
Warning message:
In formals(fun) : argument is not a function


Hope this helps,

Rui Barradas


Às 18:26 de 06/10/2018, Laurent Gautier escreveu:

> 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]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Warning when calling formals() for `[`.

Rui Barradas
Hello,

I forgot to ask you to also try to break the `sum` instruction into its
components:

args(`sum`)


does return a function. Therefore formals(args(`sum`)) returns something
useable and no warning.

Rui Barradas

Às 18:42 de 06/10/2018, Rui Barradas escreveu:

> Hello,
>
> I believe that this is maybe not a *feature* but at least expected
> behaviour.
>
> The call formals(args(`[`)) breaks down to
>
>
>  > args(`[`)
> NULL
>  > formals(NULL)
> NULL
> Warning message:
> In formals(fun) : argument is not a function
>
>
> Hope this helps,
>
> Rui Barradas
>
>
> Às 18:26 de 06/10/2018, Laurent Gautier escreveu:
>> 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]]
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Warning when calling formals() for `[`.

lgautier
In reply to this post by Rui Barradas
Hi,

Thanks for the note. How would explain the following snippet taken from
`formals` doc page (the code comment is also from that doc) ?

## formals returns NULL for primitive functions.  Use it in combination with
     ## args for this case.
     is.primitive(`+`)
     formals(`+`)
     formals(args(`+`))



Le sam. 6 oct. 2018 à 13:42, Rui Barradas <[hidden email]> a écrit :

> Hello,
>
> I believe that this is maybe not a *feature* but at least expected
> behaviour.
>
> The call formals(args(`[`)) breaks down to
>
>
>  > args(`[`)
> NULL
>  > formals(NULL)
> NULL
> Warning message:
> In formals(fun) : argument is not a function
>
>
> Hope this helps,
>
> Rui Barradas
>
>
> Às 18:26 de 06/10/2018, Laurent Gautier escreveu:
> > 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]]
> >
> > ______________________________________________
> > [hidden email] mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
> >
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Warning when calling formals() for `[`.

Peter Dalgaard-2
In reply to this post by lgautier
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 <[hidden email]> 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]]
>
> ______________________________________________
> [hidden email] 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: [hidden email]  Priv: [hidden email]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Warning when calling formals() for `[`.

Rui Barradas
Hello,

I don't see why you say that the documentation seems to be wrong:


class(args(`+`))
#[1] "function"


args() on a primitive does return a closure. At least in this case it does.


Rui Barradas

Às 14:05 de 07/10/2018, Peter Dalgaard escreveu:

> 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 <[hidden email]> 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]]
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Warning when calling formals() for `[`.

Rui Barradas
In reply to this post by lgautier
Hello,

This is the *third* time I send this, the first two I had a failure
notice so if you have already received it please apologize.

I believe this is consistent with the doc.
   From section Value:

formals returns the formal argument list of the function specified, as a
pairlist, or NULL for a non-function or primitive.


So since `+` is primitive formals is expected to return NULL.
Now, as for formals(args(`+`)) once again break it down to its two parts.

   > args(`+`)
function (e1, e2)
NULL


Now pass the return value to formals.

   > formals(function (e1, e2) NULL)
$e1


$e2


(I first tried this last call with the argument between back ticks and
it didn't work, I wonder why.)


Hope this helps,

Rui Barradas


Às 18:52 de 06/10/2018, Laurent Gautier escreveu:

> Hi,
>
> Thanks for the note. How would explain the following snippet taken from
> `formals` doc page (the code comment is also from that doc) ?
>
> ## formals returns NULL for primitive functions.  Use it in combination with
>       ## args for this case.
>       is.primitive(`+`)
>       formals(`+`)
>       formals(args(`+`))
>
>
>
> Le sam. 6 oct. 2018 à 13:42, Rui Barradas <[hidden email]
> <mailto:[hidden email]>> a écrit :
>
>     Hello,
>
>     I believe that this is maybe not a *feature* but at least expected
>     behaviour.
>
>     The call formals(args(`[`)) breaks down to
>
>
>       > args(`[`)
>     NULL
>       > formals(NULL)
>     NULL
>     Warning message:
>     In formals(fun) : argument is not a function
>
>
>     Hope this helps,
>
>     Rui Barradas
>
>
>     Às 18:26 de 06/10/2018, Laurent Gautier escreveu:
>      > 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]]
>      >
>      > ______________________________________________
>      > [hidden email] <mailto:[hidden email]> mailing list
>      > https://stat.ethz.ch/mailman/listinfo/r-devel
>      >
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Warning when calling formals() for `[`.

lgautier
In reply to this post by Rui Barradas
Note that having "function" in its class attribute does not make an object
a primitive.
For example:

> class(`[`)
[1] "function"
> is.primitive(`[`)
[1] TRUE
> class(`rnorm`)
[1] "function"
> is.primitive(`rnorm`)
[1] FALSE


Le dim. 7 oct. 2018 à 10:04, Rui Barradas <[hidden email]> a écrit :

> Hello,
>
> I don't see why you say that the documentation seems to be wrong:
>
>
> class(args(`+`))
> #[1] "function"
>
>
> args() on a primitive does return a closure. At least in this case it does.
>
>
> Rui Barradas
>
> Às 14:05 de 07/10/2018, Peter Dalgaard escreveu:
> > 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 <[hidden email]> 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]]
> >>
> >> ______________________________________________
> >> [hidden email] mailing list
> >> https://stat.ethz.ch/mailman/listinfo/r-devel
> >
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Warning when calling formals() for `[`.

Peter Dalgaard-2
In reply to this post by Rui Barradas


> On 7 Oct 2018, at 16:04 , Rui Barradas <[hidden email]> wrote:
>
> Hello,
>
> I don't see why you say that the documentation seems to be wrong:
>
>
> class(args(`+`))
> #[1] "function"
>
>
> args() on a primitive does return a closure. At least in this case it does.

But in this case it doesn't:

> is.primitive(get("["))
[1] TRUE
> class(args(get("[")))
[1] "NULL"

Or, for that matter:

> is.primitive(`[`)
[1] TRUE
> class(args(`[`))
[1] "NULL"

-pd

>
>
> Rui Barradas
>
> Às 14:05 de 07/10/2018, Peter Dalgaard escreveu:
>> 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 <[hidden email]> 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]]
>>>
>>> ______________________________________________
>>> [hidden email] 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: [hidden email]  Priv: [hidden email]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Warning when calling formals() for `[`.

Rui Barradas
In reply to this post by lgautier
Hello,

Inline.

Às 15:07 de 07/10/2018, Laurent Gautier escreveu:
> Note that having "function" in its class attribute does not make an
> object a primitive.

I did not say it does.

What Peter said is that "args() on a primitive should yield a closure"
and this return value is indeed a closure.

Rui Barradas

> For example:
>
>  > class(`[`)
> [1] "function"
>  > is.primitive(`[`)
> [1] TRUE
>  > class(`rnorm`)
> [1] "function"
>  > is.primitive(`rnorm`)
> [1] FALSE
>
>
> Le dim. 7 oct. 2018 à 10:04, Rui Barradas <[hidden email]
> <mailto:[hidden email]>> a écrit :
>
>     Hello,
>
>     I don't see why you say that the documentation seems to be wrong:
>
>
>     class(args(`+`))
>     #[1] "function"
>
>
>     args() on a primitive does return a closure. At least in this case
>     it does.
>
>
>     Rui Barradas
>
>     Às 14:05 de 07/10/2018, Peter Dalgaard escreveu:
>      > 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 <[hidden email]
>     <mailto:[hidden email]>> 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]]
>      >>
>      >> ______________________________________________
>      >> [hidden email] <mailto:[hidden email]> mailing list
>      >> https://stat.ethz.ch/mailman/listinfo/r-devel
>      >
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Warning when calling formals() for `[`.

Rui Barradas
In reply to this post by Peter Dalgaard-2
Hello,

This is because args(`[`) returns NULL and class(NULL) is NULL.
So the question would be why is the return value of args(`[`) NULL?

Rui Barradas

Às 15:14 de 07/10/2018, Peter Dalgaard escreveu:

>
>
>> On 7 Oct 2018, at 16:04 , Rui Barradas <[hidden email]> wrote:
>>
>> Hello,
>>
>> I don't see why you say that the documentation seems to be wrong:
>>
>>
>> class(args(`+`))
>> #[1] "function"
>>
>>
>> args() on a primitive does return a closure. At least in this case it does.
>
> But in this case it doesn't:
>
>> is.primitive(get("["))
> [1] TRUE
>> class(args(get("[")))
> [1] "NULL"
>
> Or, for that matter:
>
>> is.primitive(`[`)
> [1] TRUE
>> class(args(`[`))
> [1] "NULL"
>
> -pd
>
>>
>>
>> Rui Barradas
>>
>> Às 14:05 de 07/10/2018, Peter Dalgaard escreveu:
>>> 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 <[hidden email]> 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]]
>>>>
>>>> ______________________________________________
>>>> [hidden email] mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Warning when calling formals() for `[`.

Emil
Hello,

I agree the documentation of args can be improved, but the main question is what the return should be.
I guess the reason args() returns NULL is because of the way argument-matching works for primitives: there is a lot going on under the hood, and what arguments are/are not acceptable for `[` can't be stated as straightforward as we can with other functions.
Note also the difference in printing "sum" and "[": sum first prints "function(..., na.rm=FALSE)", whereas `[` jumps straight to the body. And this is not an artefact of printing it, as makes overwriting it makes clear:
`[` <- function(x, i, j, ..., drop=FALSE) .Primitive("[")
exhibited very strange behaviour, where you need to call it twice/nested: 1[2] returns a primitive function, to get it to do its job you need 1[2](df, 3, 4) instead of df[3,4].
So general advice would probably be to stay away from messing with arguments with primitives, as ?args already hints at: " mainly used interactively (...). For programming, consider using formals instead."
Basically, primitives are optimized and down to the core, which probably means the concept of an argument-list may not be as clear as it is with "normal" functions.
So working with args() on primitives comes with some risks, which probably is the reason that formals() always return NULL in that case.
What is your use case?
If you really need a return value, I think you could catch NULL-values, something like this:
args <- function(name) {
  if(is.character(name)) name <- get(name, parent.frame(), mode='function')
  if(!is.function(name)) return(NULL)
  ret <- base::args(name)
  if(is.null(ret) && is.primitive(name)) {
    ret <- function(...) NULL
    environment(ret) <- parent.frame()
  }
  return(ret)
}

Which would just return "function(...) NULL" for args("["), which is of the expected class, but does not give you any real information. Would that help you?
Otherwise, to get to know the arguments there is of course "?"
And note that if there is a dispatch, it's possible to get the argument-list of a specific method, e.g. args(`[.data.frame`) works as expected (as it is not a primitive)


Best regards,
Emil Bode

On 07/10/2018, 16:34, "R-devel on behalf of Rui Barradas" <[hidden email] on behalf of [hidden email]> wrote:

    Hello,
   
    This is because args(`[`) returns NULL and class(NULL) is NULL.
    So the question would be why is the return value of args(`[`) NULL?
   
    Rui Barradas
   
    Às 15:14 de 07/10/2018, Peter Dalgaard escreveu:
    >
    >
    >> On 7 Oct 2018, at 16:04 , Rui Barradas <[hidden email]> wrote:
    >>
    >> Hello,
    >>
    >> I don't see why you say that the documentation seems to be wrong:
    >>
    >>
    >> class(args(`+`))
    >> #[1] "function"
    >>
    >>
    >> args() on a primitive does return a closure. At least in this case it does.
    >
    > But in this case it doesn't:
    >
    >> is.primitive(get("["))
    > [1] TRUE
    >> class(args(get("[")))
    > [1] "NULL"
    >
    > Or, for that matter:
    >
    >> is.primitive(`[`)
    > [1] TRUE
    >> class(args(`[`))
    > [1] "NULL"
    >
    > -pd
    >
    >>
    >>
    >> Rui Barradas
    >>
    >> Às 14:05 de 07/10/2018, Peter Dalgaard escreveu:
    >>> 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 <[hidden email]> 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]]
    >>>>
    >>>> ______________________________________________
    >>>> [hidden email] mailing list
    >>>> https://stat.ethz.ch/mailman/listinfo/r-devel
    >
   
    ______________________________________________
    [hidden email] mailing list
    https://stat.ethz.ch/mailman/listinfo/r-devel
   

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel