Re: [R] What does m$... mean?

2003-08-14 Thread Prof Brian Ripley
On Wed, 13 Aug 2003, Richard A. O'Keefe wrote:

> While reading through some of the R source code, I have come
> across forms such as
> m$...
> m$... <- e
> and I wondered what they meant.
> 
> ?"$" mentions x$name, but not $... 

... is a name, a special one in the context of function calls.

> All it says is
> 
>  The operators `$' and `$<-' do not evaluate their second argument.
>   It is translated to a string and that string is used to locate
>  the correct component of the first argument.
> 
> Does this mean that m$... is the same as m$"..."
> and m$... <- e is the same as m$"..." <- e?

Yes.

> That's what it seems to do when I try it on some small data frames,
> but is that ALL there is to it, or is there some special magic going
> on?  Is there any connection with the use of ... in formal and actual
> parameter lists, or is it just accidental?  Why would anyone _want_
> to use $... ?

To add or to change (but almost always to remove) the component of a list
named ...  .  And they occur frequently in matched calls.

This construction (like many others) is explained in `S Programming': it 
seems you may find it enlightening.

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

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] What does m$... mean?

2003-08-14 Thread Spencer Graves
"a$b" = "a[['b']] = attribute "b" of list "a".

A basic object in R is a list, and the "$" operator provides one means 
of accessing named attributes of a list.

	  Beginning with R 1.7, objects can also have "slots", which are 
accessed as "[EMAIL PROTECTED]".  I have yet to understand why "slots" were 
introduced;  perhaps someone else will explain this.

hope this helps.
spencer graves
Richard A. O'Keefe wrote:
While reading through some of the R source code, I have come
across forms such as
m$...
m$... <- e
and I wondered what they meant.
?"$" mentions x$name, but not $... 
All it says is

 The operators `$' and `$<-' do not evaluate their second argument.
  It is translated to a string and that string is used to locate
 the correct component of the first argument.
Does this mean that m$... is the same as m$"..."
and m$... <- e is the same as m$"..." <- e?
That's what it seems to do when I try it on some small data frames,
but is that ALL there is to it, or is there some special magic going
on?  Is there any connection with the use of ... in formal and actual
parameter lists, or is it just accidental?  Why would anyone _want_
to use $... ?
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] What does m$... mean?

2003-08-14 Thread Prof Brian Ripley
On Tue, 12 Aug 2003, Spencer Graves wrote:

> "a$b" = "a[['b']] = attribute "b" of list "a".

(Not quite always.  First, it is `component' not `attribute' and second $ 
and [[ ]] do behave differently, e.g. for data frames in 1.7.x.)

> A basic object in R is a list, and the "$" operator provides one means 
> of accessing named attributes of a list.
> 
> Beginning with R 1.7, objects can also have "slots", which are 
> accessed as "[EMAIL PROTECTED]".  I have yet to understand why "slots" were 
> introduced;  perhaps someone else will explain this.

Slots are part of objects which have formal (S4) classes, made using the 
`methods' package (so have been around since at least R 1.4.0).
They are an implementation of the ideas of Chambers (1998).  Formally 
classed objects are not just lists: they have rules for the number, names 
and types of the slots. (Currently they are lists, but that's an 
implementation detail.)

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

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help