[R] How to set an argument such that a function treats it as missing?

Gabor Grothendieck ggrothendieck at gmail.com
Sat Nov 13 12:29:10 CET 2010

On Sat, Nov 13, 2010 at 3:14 AM, Marius Hofert <m_hofert at web.de> wrote:
> Dear expeRts,
> I would like to call a function f from a function g with or without an argument.
> I use missing() to check if the argument is given. If it is not given, can I set
> it to anything such that the following function call (to f) behaves as if the argument
> isn't given? It's probably best described by a minimal example (see below).
> The reason why I want to do this is, that I do not have to distinguish between the
> cases when the argument is given or not. By setting it to something (what?) in the
> latter case, I can use the same code in the subsequent part of the function.

You can pass missing values:

f <- function(x) g(x)
g <- function(x) missing(x)
f(3) # FALSE
f() # 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