I encountered some strange behaviour that I don't quite understand. I often set non-required parameters as NULL in a function, so that I can check them using is(!missing).
However, when I have one function pass a NULL value to another function, the NULL value gets interpreted as non-NULL:
fun1 <- function(value=NULL){
if (missing(value)) stop("\n[!] Must provide a value. Exiting.")
cat("Value is missing: ", missing(value), "value: ", value, "\n")
}
wrapper <- function(value=NULL){
ret <- fun1(value=value)
cat(ret)
}
wrapper(value = "Here")
# -> Value is missing: FALSE value: Here
# I expected this to print "Value is missing: TRUE"
wrapper(value = NULL)
# -> Value is missing: FALSE value:
Can anyone shed some light on this (and how I can fix the problem)?