Re: [R] data encapsulation with classes

From: Roger Bivand <Roger.Bivand_at_nhh.no>
Date: Sun 08 Apr 2007 - 13:08:18 GMT


On Sun, 8 Apr 2007, Peter Williams wrote:

> Hi All,
>
> I'm new to R from a C and Octave/Matlab background. I am trying to
> construct some classes in R to which I want to attach pieces of data.
> First, is attr(obj, 'member name') <- data the accepted way of doing
> this?

No, it isn't. You seem to be trying to deduce new-style classes from a representation used before R 2.4, but in any case it would not be sensible. Please consult John M. Chambers. Programming with Data. Springer, New York, 1998, and/or William N. Venables and Brian D. Ripley. S Programming. Springer, New York, 2000, or for a shorter online resource:

http://www.stat.auckland.ac.nz/S-Workshop/Gentleman/Methods.pdf

>
> Second, having attached member data with attr is there anything wrong
> with accessing it by the asperand (@), i.e.
>
> > t = ""
> > attr(t, 'test') <- 4
> > t@test
> [1] 4
>
> I can't find any documentation on using the asperand to access
> attributes like this. I saw it in a piece of code as I was googling
> around trying to find some information on attaching data to a class
> in R. Is this deprecated? Is this poor form? If anyone has some
> suggestions please let me know.
>
> Thank you
>
> ______________________________________________
> 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.
>

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand@nhh.no

______________________________________________
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.
Received on Sun Apr 08 23:13:16 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sun 08 Apr 2007 - 14:31:01 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.