The following R function
tmp <- function(p)
rep(0, length.out = p)
puzzles me, since
> tmp()
[1] 0
I would expect an error in the call, since p
is missing. The documentation for rep
says that
Function rep is a primitive, but (partial) matching of argument names is performed as for normal functions. You can no longer pass a missing argument to e.g. length.out.
I don't understand the logic here. Why does rep
seem to ignore that p
is missing?
R version 3.0.2 (2013-09-25)
The missing argument is an object that triggers an error if and only if it is the result of evaluating a symbol. No error is produced when a function call evaluates to the missing argument object.
14.1 Functions in RFunctions can be passed as arguments to other functions. This is very handy for the various apply functions, like lapply() and sapply() . Functions can be nested, so that you can define a function inside of another function.
In the documentation, I see:
The default behaviour is as if the call was
rep(x, times = 1, length.out = NA, each = 1)
But it does not apply for rep.int
, which requires times argument:
>rep(0,)
[1] 0
>rep.int(0,)
Error in rep.int(0, ) : argument "times" is missing, with no default
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With