On Wed, Feb 2, 2011 at 7:25 PM, Peter Langfelder <peter.langfel...@gmail.com> wrote: > On Wed, Feb 2, 2011 at 7:22 PM, Nick Matzke <mat...@berkeley.edu> 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)
Nope, e.g. > z <- list(a=NULL) > str(z) List of 1 $ a: NULL Instead, test by: > is.element("a", names(z)) [1] TRUE or equivalently > ("a" %in% names(z)) [1] TRUE or > any(names(z) == "a") [1] TRUE My $.02 /Henrik > > Peter > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.