如果存在于R中使用此

dis*_*ive 1 dictionary r

我想知道变量是否存在 - 即我创建的变量.

if(exists(this.mydict))
{ //append my dict
}else
{
// initialize dict
}
Run Code Online (Sandbox Code Playgroud)

麻烦就是失败了

Error in exists(this.mydict)
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

如何扩展exists函数以使用以下内容:

任何想法我将如何扩展到这一点,看看是否也存在嵌套字典.即例如:if(exists("mylists[[index]]['TSI']")),其中mylists对象是字典查找,也希望包含嵌套字典.

dig*_*All 6

exists() function接受带有变量名的字符参数:

if(exists("this.mydict")){
    # you can use this.mydict here
}else{
    # initialize this.mydict
    # e.g. this.mydict <- "some value here"
}
Run Code Online (Sandbox Code Playgroud)