This function silently handles special cases for which is.null() and is.na() may return a warning,
such as functions objects or environments.
(e.g. the warning "Warning message: In is.na(g) : is.na() applied to non-(list or vector) of type 'closure')"