Re: [R] Attributes or list programming "efficiency"

From: Don MacQueen <macq_at_llnl.gov>
Date: Wed, 14 May 2008 20:11:45 -0700

At 2:26 PM -0400 5/14/08, Gabor Grothendieck wrote:
>The key difference is inheritance.
>
>Objects consisting of data frames with attributes, including a class attribute
>such as c("myclass", "data.frame), can inherit data frame methods but a list
>with a data frame component will require entirely new methods to be
>constructed
>for everything.
>

Or always specify the data frame element of the list, instead of the list, when writing expressions that need the dataframe. Which could be a pain!

For the attributes approach, one will have to watch for actions that remove unexpected attributes. For example, if you have two data frames, each with your own added attribute, what will happen to the attributes if you merge() them?

You might check the Hmisc package; as I recall there are some features in it for adding attributes (e.g., "units", though I don't remember for sure).

-Don

>
>
>On Wed, May 14, 2008 at 2:15 PM, Bert Gunter <gunter.berton@gene.com> wrote:
>> R-Fellow Travellers:
>>
>> Asked from the perspective of a software development amateur ...
>>
>> Suppose one wishes to create data structures that have both data and
>> metadata -- e.g. a data.frame and details about where, when, and by whom the
>> data were gathered (specifics not important here).
>>
>> 1. Is there any inherent processing advantage in R in representing this as a
>> list that contains both the data and metadata as components vs as a
>> data.frame with the metadata as attributes?
>>
>> 2. Is there a compelling software architecture argument to favor one vs the
>> other?
>>
>> I suspect the answer is no in both cases, but I thought I'd ask. This seems
>> to be mainly relevant for S3 programming, as in S4 one might stick the info
>> into different slots (if one wishes to dispatch on them).
>>
>> Cheers to all,
>>
>> Bert Gunter
>> Genentech
>>
>>
>>
>>
>>
>>
>>
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help_at_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_at_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.

-- 
---------------------------------
Don MacQueen
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062
macq_at_llnl.gov

______________________________________________
R-help_at_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.
Received on Thu 15 May 2008 - 05:41:30 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 15 May 2008 - 07:30:38 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive