19

I am trying to skip steps loading data from large files if this has already been done earlier. Since the data ends up in (for example) mydf, I thought I could do:

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

I got this from How to check if object (variable) is defined in R? and https://stat.ethz.ch/R-manual/R-devel/library/base/html/exists.html

However R Studio simply complains with

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

Why does it complain instead of just returning 'true' or 'false'? Any tips appreciated.

Community
  • 1
  • 1
rstruck
  • 1,174
  • 4
  • 17
  • 27

1 Answers1

49

You should use exists("mydf") instead exists(mydf)

Fedorenko Kristina
  • 2,607
  • 2
  • 19
  • 18