[R] Testing for arguments in a function
Gabor Grothendieck
ggrothendieck at gmail.com
Mon Sep 26 23:22:21 CEST 2011
On Mon, Sep 26, 2011 at 3:39 PM, Gene Leynes <gleynes at gmail.com> wrote:
> I don't understand how this function can subset by i when i is missing....
>
> ## My function:
> myfun = function(vec, i){
> ret = vec[i]
> ret
> }
>
> ## My data:
> i = 10
> vec = 1:100
>
> ## Expected input and behavior:
> myfun(vec, i)
>
> ## Missing an argument, but error is not caught!
> ## How is subsetting even possible here???
> myfun(vec)
>
>
> Is there a way to check for missing function arguments, *and* which function
> arguments are missing?
>
R lets you pass missing arguments down from one function call to
another in such a way that they retain their missingness:
> f <- function(x) g(x)
> g <- function(x) missing(x)
> f()
[1] TRUE
--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
More information about the R-help
mailing list