From ruipb@rr@d@@ @ending from @@po@pt  Sun Oct  7 16:07:17 2018
From: ruipb@rr@d@@ @ending from @@po@pt (Rui Barradas)
Date: Sun, 7 Oct 2018 15:07:17 +0100
Subject: [Rd] Warning when calling formals() for `[`.
In-Reply-To: <CA+JCgN3iXFhgeEA4Ozmw-VutK=VPXnF0dxTFV9C6AZJF+p1LjA@mail.gmail.com>
References: <CA+JCgN254QaHVepo03ZuGLsatwmjfDSnUP3yq43N6TguBdWN5g@mail.gmail.com>
 <f5d15068-0776-2b5e-11d7-b1ae6ffc1d3b@sapo.pt>
 <CA+JCgN3iXFhgeEA4Ozmw-VutK=VPXnF0dxTFV9C6AZJF+p1LjA@mail.gmail.com>
Message-ID: <26e3fea8-5849-1653-2768-1a8021ba8ab5@sapo.pt>

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 <ruipbarradas at sapo.pt 
> <mailto:ruipbarradas at sapo.pt>> 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]]
>      >
>      > ______________________________________________
>      > R-devel at r-project.org <mailto:R-devel at r-project.org> mailing list
>      > https://stat.ethz.ch/mailman/listinfo/r-devel
>      >
>



[Rd] Warning when calling formals() for `[`.
Rui Barradas