Re: [R] how to check if an attribute exists

2011-02-02 Thread Henrik Bengtsson
On Wed, Feb 2, 2011 at 7:25 PM, Peter Langfelder wrote: > On Wed, Feb 2, 2011 at 7:22 PM, Nick Matzke wrote: >> Oh wait, this basically does it: >> >>> if ("a" %in% attributes(z)$names) >> + print(TRUE) >> [1] TRUE >> >> (but there may be a better way) > > If z is a list, you can test > > is.null

Re: [R] how to check if an attribute exists

2011-02-02 Thread Peter Langfelder
On Wed, Feb 2, 2011 at 7:22 PM, Nick Matzke wrote: > Oh wait, this basically does it: > >> if ("a" %in% attributes(z)$names) > + print(TRUE) > [1] TRUE > > (but there may be a better way) If z is a list, you can test is.null(z$a) Peter __ R-help@r-pr

Re: [R] how to check if an attribute exists

2011-02-02 Thread Nick Matzke
Oh wait, this basically does it: > if ("a" %in% attributes(z)$names) + print(TRUE) [1] TRUE (but there may be a better way) Cheers! Nick On 2/2/11 7:20 PM, Nick Matzke wrote: I am dealing with an object that sometimes has a certain attribute, sometimes doesn't. How do I check for this? "exist

[R] how to check if an attribute exists

2011-02-02 Thread Nick Matzke
I am dealing with an object that sometimes has a certain attribute, sometimes doesn't. How do I check for this? "exists" doesn't work... === > z=c() > z$a = c("c", "d", "f") > z $a [1] "c" "d" "f" > exists("z") [1] TRUE > exists("z$a") [1] FALSE === .