[R] Existence of an object

Rainer Schuermann rainer.schuermann at gmx.net
Sat Nov 7 06:25:36 CET 2015


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
> 
> 
>



More information about the R-help mailing list