if (!"name" %in% names(attributes(dat))) { ... } /Henrik
On 2/26/07, Michael Toews <[EMAIL PROTECTED]> wrote: > In R 2.5.0 (r40806), one of the change is to allow partial matching of > "name" in the attr function. However, how can I tell if I have an exact > match or not? > > For example, checking to see if an object has a "name" attribute, then > giving it one if it doesn't: > > dat <- data.frame(x=1:10,y=rnorm(10)) > if(is.null(attr(dat,"name"))) > attr(dat,"name") <- "Site 1" > str(dat) > > (This example works in R < 2.5) Although there is no "name" attribute to > the data.frame, it partially matches to "names", resulting in not > setting the attribute. (Personally, I think this change in the "attr" > function is not desirable, and much prefer exact matches to avoid > unintentional errors). > > How can I tell if this is an exact match? Is there a way to force an > exact match? > > Thanks. > > +mt > > ______________________________________________ > R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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.