R : Check if R object exists before creating it

r

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.

Best Solution

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

Related Question