# Works, but the ifs are repetitive
if (exists('x')) {
if (!is.null(x)) {
if (!is.na(x)) {
print(y)
}
}
}
# Fatal error if x does not exist due to is.null(x) and is.na(x) checks
# if (exists('x')) should return FALSE and be done, but it does not
if (exists('x') & !is.null(x) & !is.na(x)) { print(y) }
Is there a way to do this more elegantly, maybe something akin to function(x) {y}
?