[R] Testing for existence inside a function
albmont at centroin.com.br
Tue May 15 22:00:41 CEST 2007
Duncan Murdoch wrote:
>> Try this:
>> f <- function(x) x + 1
>> The error message is (almost) the same, and it happens when
>> parsing the line. There's no way to change f to change this.
> That description is true in some languages, but not in R. R doesn't
> check that args to functions are valid until it needs to use them.
> For example:
> > f <- function(y) 1 # doesn't care if y exists
> > f(y.does.not.exist)
>  1
Ok, I guess R optimizes every call to f, ignoring its arguments
f <- function(y) 1 # doesn't care if y exists
g <- function() cat("g was called\n")
# g was not called
f1 <- function(x, y) if (x == 0) y else 1
The y-argument is never called.
So maybe it _might_ be possible to test if y exists inside the
More information about the R-help