本文介绍了验证对象在R中的函数中是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想确定对象是否存在于R中的函数中:
I want to determine whether an object exists inside a function in R:
foo <- function() {
y <- "hello"
if (exists(y, envir = sys.frame())) print(y)
}
foo()
我认为添加envir = sys.frame()
可以解决问题.还尝试了envir = environment()
I thought adding the envir = sys.frame()
would do the trick. Also tried envir = environment()
期望
foo()
"hello"
推荐答案
您应已选中?exists
:
Usage:
exists(x, where = -1, envir = , frame, mode = "any",
inherits = TRUE)
Arguments:
x: a variable name (given as a character string).
执行exists("y")
这篇关于验证对象在R中的函数中是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!