[R] getting attributes of list without the "names".

Jeroen Ooms jeroenooms at gmail.com
Tue Mar 1 05:17:28 CET 2011


I am trying to encode arbitrary S3 objects by recursively looping over the
object and all its attributes. However, there is an unfortunate feature of
the attributes() function that is causing trouble. From the manual for
?attributes:

The names of a pairlist are not stored as attributes, but are reported as if
they were (and can be set by the replacement method for attributes).

Now because of this, my program ends up in infinite recursion, because it
will try to encode
attributes(attributes(attributes(attributes(list(foo=123)))) etc. I can't
remove the 'names' attribute, because this will actually affect the list
structure. And even when I do:

attributes(attributes(obj)[names(attributes(obj)) != "names"])

This will keep giving me a named list. Is there any way I can get the
attributes() of a list without it reporting the names of a list as
attributes? I.e it should hold that:

atr1 <- attributes(list(foo="bar"));
atr2 <- attributes(list());
identical(atr1,atr2);



-- 
View this message in context: http://r.789695.n4.nabble.com/getting-attributes-of-list-without-the-names-tp3329209p3329209.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list