Re: [R] data encapsulation with classes

2007-04-09 Thread Prof Brian Ripley
On Sun, 8 Apr 2007, hadley wickham wrote:

 On 4/8/07, Roger Bivand [EMAIL PROTECTED] wrote:
 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,

(actually, still used)

 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

 Unfortunately, all of those references are at least 4 years out of
 date when it comes to S4 methods.  Is there any comprehensive
 reference of the current implementation of the S4 OO system apart from
 the source code?

Not that I know of, and it is a moving target.  (E.g. I asked recently 
about some anomalies in the S4 bit introduced for 2.4.0 and what the 
intended semantics are.)  I've said before that I believe we can only 
help solve some of the efficiency issues with S4 if we have a technical 
manual.

It is unfair to pick out S4 here, but the 'R Internals' manual is an 
attempt to document important implementation details (mainly by studying 
the code), and that has only got most of the way through src/main/*.c.

-- 
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
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.


Re: [R] data encapsulation with classes

2007-04-09 Thread Martin Maechler
 BDR == Prof Brian Ripley [EMAIL PROTECTED]
 on Mon, 9 Apr 2007 08:24:32 +0100 (BST) writes:

BDR On Sun, 8 Apr 2007, hadley wickham wrote:
 On 4/8/07, Roger Bivand [EMAIL PROTECTED] wrote:
 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,

BDR (actually, still used)

 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

  Unfortunately, all of those references are at least 4
 years out of date when it comes to S4 methods.  Is there
 any comprehensive reference of the current implementation
 of the S4 OO system apart from the source code?

?Methods {i.e. help(Methods)} is not about the *implementation*
but still explains quite a bit about the method dispatch part of
S4.  It has had a URL to for the How S4 Methods Work technical
report by John Chambers; I've now also added a link to that from
http://developer.R-project.org/ (will only be active in ~ a day).

Martin

BDR Not that I know of, and it is a moving target.  (E.g. I
BDR asked recently about some anomalies in the S4 bit
BDR introduced for 2.4.0 and what the intended semantics
BDR are.)  I've said before that I believe we can only help
BDR solve some of the efficiency issues with S4 if we have
BDR a technical manual.

BDR It is unfair to pick out S4 here, but the 'R Internals'
BDR manual is an attempt to document important
BDR implementation details (mainly by studying the code),
BDR and that has only got most of the way through
BDR src/main/*.c.

BDR -- Brian D. Ripley, [EMAIL PROTECTED] Professor of
BDR Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
BDR University of Oxford, Tel: +44 1865 272861 (self) 1
BDR South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG,
BDR UK Fax: +44 1865 272595

__
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.


[R] data encapsulation with classes

2007-04-08 Thread Peter Williams
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?

Second, having attached member data with attr is there anything wrong  
with accessing it by the asperand (@), i.e.

  t = 
  attr(t, 'test') - 4
  [EMAIL PROTECTED]
[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.


Re: [R] data encapsulation with classes

2007-04-08 Thread Roger Bivand
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
   [EMAIL PROTECTED]
 [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: [EMAIL PROTECTED]

__
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.


Re: [R] data encapsulation with classes

2007-04-08 Thread hadley wickham
On 4/8/07, Roger Bivand [EMAIL PROTECTED] wrote:
 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

Unfortunately, all of those references are at least 4 years out of
date when it comes to S4 methods.  Is there any comprehensive
reference of the current implementation of the S4 OO system apart from
the source code?

Hadley

__
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.