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
> On 7 Oct 2018, at 16:04 , Rui Barradas 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:
>
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 wrote:
Hello,
I don't see why you say that the
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
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 a écrit :
> Hello,
>
> I
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
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
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(`+`)
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
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,
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`))
$...
11 matches
Mail list logo