[R] exact matching of names in attr

Michael Toews mwtoews at sfu.ca
Mon Feb 26 20:33:49 CET 2007


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



More information about the R-help mailing list