我有以下(无意义)功能,在R:
say <- function (string){
if(!exists("string")){
stop("no output string was specified")
}
cat(string)
}
Run Code Online (Sandbox Code Playgroud)
在检查字符串对象实际存在时,这一切都很好.但是,如果同名的对象已经在工作空间中浮动,它将忽略该错误,即使该函数中未定义该错误.
我可以这样做,所以exists()函数只能在对象的函数空间中查找吗?
你在找missing.其他人做这样的事情:
say <- function(string=NULL){
if(is.null(string)){
stop("no output string was specified")
}
cat(string)
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
554 次 |
| 最近记录: |