This question may sound silly for the toy example I provide but it actually make sense in the real situation I'm facing.
Assume function f
such as:
f <- function(x) {
if (missing(x))
"something very nice happens if x is missing"
else
"something else that is also very nice happens if x not missing"
}
Sometimes I need to call f
just as f()
but sometimes with specified arguments.
One way to do it (based on some condition cond
):
if (cond) f(1) else f()
But such construction will grow in complexity (like a cartesian product) with the need of additional arguments. I would therefore like to call f
this way:
f(if (cond) 1 else *)
where *
is supposed to be "nothing".
If I were the owner of f
I could rewrite it as:
f <- function(x = NULL) {
if (null(x))
"something very nice happens if x is null"
else
"something else that is also very nice happens if x not null"
}
and use * = NULL
. Unfortunately I can not do this so another way would be much appreciated!
P.S. This is my first question on StackOverflow :-) D.S.