I have a variable meanedf which may sometimes not be defined due to a complex set of circumstances. I would like to be able to find out whether or not it exists, and then branch appropriately in my code. I had hoped to be able to use is.null() or exists() but neither of these returns TRUE or FALSE which is the behaviour I would like, so that I can write some appropriate branching code. is.null(meanedf) Error: object 'meanedf' not found No suitable frames for recover() exists(meanedf) Error in exists(meanedf) : object 'meanedf' not found I would like some code which returns TRUE when meanedf exists and FALSE when it doesn't. Thanks, and regards, Margaret Donald -- Margaret Donald Post Doctoral researcher University of New South Wales margaret.donald at unsw.edu.au 0405 834 550 [[alternative HTML version deleted]]
For me, "meanedf" %in% ls() works: meanedf <- 1 "meanedf" %in% ls() [1] TRUE rm( meanedf ) "meanedf" %in% ls() [1] FALSE Rgds, Rainer On Saturday 07 November 2015 04:48:04 Margaret Donald wrote:> I have a variable meanedf which may sometimes not be defined due to a > complex set of circumstances. > I would like to be able to find out whether or not it exists, and then > branch appropriately in my code. > > I had hoped to be able to use is.null() or exists() but neither of these > returns TRUE or FALSE which is the behaviour I would like, so that I can > write some appropriate branching code. > > is.null(meanedf) > Error: object 'meanedf' not found > No suitable frames for recover() > > exists(meanedf) > Error in exists(meanedf) : object 'meanedf' not found > > I would like some code which returns TRUE when meanedf exists and FALSE > when it doesn't. > > Thanks, and regards, > Margaret Donald > > >
Quotation marks help also for exists(): exists( "meanedf" ) [1] TRUE On Saturday 07 November 2015 04:48:04 Margaret Donald wrote:> I have a variable meanedf which may sometimes not be defined due to a > complex set of circumstances. > I would like to be able to find out whether or not it exists, and then > branch appropriately in my code. > > I had hoped to be able to use is.null() or exists() but neither of these > returns TRUE or FALSE which is the behaviour I would like, so that I can > write some appropriate branching code. > > is.null(meanedf) > Error: object 'meanedf' not found > No suitable frames for recover() > > exists(meanedf) > Error in exists(meanedf) : object 'meanedf' not found > > I would like some code which returns TRUE when meanedf exists and FALSE > when it doesn't. > > Thanks, and regards, > Margaret Donald > > >