How to check if object (variable) is defined in R?

前端 未结 6 1407
被撕碎了的回忆
被撕碎了的回忆 2020-11-28 20:02

I\'d like to check if some variable is defined in R - without getting an error. How can I do this?

My attempts (not successful):

> is.na(ooxx)
Err         


        
6条回答
  •  一生所求
    2020-11-28 20:49

    if you are inside a function, missing() is what you want.

    exchequer = function(x) {
        if(missing(x)){
            message("x is missing… :-(")
        }
    }
    
    exchequer()
    x is missing… :-(
    

提交回复
热议问题