【问题标题】:R : Check if R object exists before creating itR : 在创建之前检查 R 对象是否存在
【发布时间】:2015-03-28 21:39:59
【问题描述】:

如果之前已经完成,我正在尝试跳过从大文件加载数据的步骤。由于数据以(例如)mydf 结尾,我想我可以这样做:

if( !exists(mydf) )
{
  #... steps to do loading here.
}

我从How to check if object (variable) is defined in R?https://stat.ethz.ch/R-manual/R-devel/library/base/html/exists.html 得到这个

但是 R Studio 只是抱怨

'Error in exists(mydf) : object 'mydf' not found

为什么它会抱怨而不是只返回“真”或“假”?任何提示表示赞赏。

【问题讨论】:

    标签: r


    【解决方案1】:

    您应该使用exists("mydf") 而不是exists(mydf)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-29
      • 2013-09-03
      • 1970-01-01
      相关资源
      最近更新 更多