Re: [Rd] returning information from functions via attributes rather than return list

From: Hadley Wickham <hadley_at_rice.edu>
Date: Wed, 04 Jan 2012 17:31:56 -0600

> Attributes are slightly harder to work with, so Simon's recommendation is
> good advice.  But in cases where you want other functions to work with the
> result, and the result isn't a named list with a class, then attributes are
> a convenient way to go.
>
> The only two snags I can think of are 1, that R uses a few attributes for
> its own purposes (e.g. "names", "dim" and "dimnames") and if you use those
> attribute names for something incompatible you'll probably run into all
> sorts of problems and 2, that S4 objects use attributes internally.  I
> wouldn't recommend using attributes on an S4 object.

Attributes are also useful when you're extending a atomic vector, and want to be able to store objects of your new class inside data frames etc.

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Wed 04 Jan 2012 - 23:37:35 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

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 05 Jan 2012 - 15:30:06 GMT.

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

list of date sections of archive