I have a function f
that takes two parameters (p1
and p2
):
If for the parameter p2
no value was passed to the function, the value of p1
^2 should be used instead. But how can I find out within the function, if a value is given or not. The problem is that the variable p2
is not initialized if there was no value. Thus I can't test for p2
being NULL
.
f <- function(p1, p2) {
if(is.null(p2)) {
p2=p1^2
}
p1-p2
}
Is it somehow possible to check if a value for p2
was passed to the function or not? (I could not find an isset()
- function or similar things.)
NULL
default alternative. Re: the EDIT you added, how would you passmissing
'ness down through the wrapper function? – Ticino