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

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Aug 13 07:31:09 CEST 2003


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 "a at b".  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,                  ripley at stats.ox.ac.uk
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, UK                Fax:  +44 1865 272595




More information about the R-help mailing list