mercredi 21 juin 2017

R Test if object exists and is not null in loop

this must be really simple but I am struggling to get the logic right.

I have an object "XXX" that is created within an initial if statement (which is in a loop).

I need to create another if layer below so that:

      if( exists("XXX") & !is.null("XXX")) { do stuff } else { do other stuff}

However, if "XXX" does not exist, I get an error because the !is.null(XXX) is evaluated.

What's a concise and reasonable way to construct this dual condition?

Aucun commentaire:

Enregistrer un commentaire