Dear R developers A question about the class 'listof', defined in package 'stats'. Other than its definition and use in the code for 'anova', we can't see that the class 'listof' is used for anything else (in recommended packages, or elsewhere). In the spatstat package we have been using a 'listof' to represent a list of spatial objects of the same class (such as point patterns, or pixel images) and we've defined a plot method. Is it OK for us to hijack an existing class in this way, or is this a violation of some future plans/ design feature of R ? We're about to publish a book on spatstat so I would much appreciate advice if we need to change it. regards Adrian Prof Adrian Baddeley FAA University of Western Australia
On 30/07/2014 04:20, Adrian Baddeley wrote:> Dear R developers > > A question about the class 'listof', defined in package 'stats'. > > Other than its definition and use in the code for 'anova',For alias.lm and aov in file aov.R, not anova.> we can't see that the class 'listof' is used for anything else > (in recommended packages, or elsewhere). > > In the spatstat package we have been using a 'listof' > to represent a list of spatial objects of the same class > (such as point patterns, or pixel images) > and we've defined a plot method. > > Is it OK for us to hijack an existing class in this way, > or is this a violation of some future plans/ design feature of R ?The class is for lists to be printed in a certain way (there are other such classes, e.g. "simple.list", "DList") and for which coef() makes sense. If your plot() method makes sense for all such lists (e.g. just calls plot() on each element) this seems fine: if not you need a more specific class inheriting from "listof". The class has been in R 'for ever' and I do not see it being changed. I've added some notes to the source files about where it is used.> > We're about to publish a book on spatstat > so I would much appreciate advice if we need to change it. > > regards > Adrian > > Prof Adrian Baddeley FAA > University of Western Australia-- 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
An interesting topic, but I'll only respond with my own experience, and that is, while 'listof' could be usefully extended there was not enough meat on the bones to want to do so. I think this is a limitation of the S3 class/method structure, as I see it. In several packages (effects, heplots, candisc, vcdExtra) I/we deal with lists of objects of a given class, and want to define methods for plot(), summary(), print(), etc. In these cases, the simplest solution was to designate a new class, e.g., 'efflist' for a list of effects in a univariate lm/glm/polr/ ... model or 'candiscList' for a list of candisc objects. Methods for the *list class could then use an apply() construct over the list items. Most recently, in the effects package, we implemented some effects plot methods for multivariate linear models. This is essentially a two-way collection of effects for terms x responses, but how to represent this in the class structure to re-use the existing code for a single effect of a given response variable? The solution used here was to define a new class, 'mlm.efflist', with new methods for this class. This works within the current S3 class scheme, but doesn't provide an extendible semantics. -Michael On 7/29/2014 11:20 PM, Adrian Baddeley wrote:> Dear R developers > > A question about the class 'listof', defined in package 'stats'. > > Other than its definition and use in the code for 'anova', > we can't see that the class 'listof' is used for anything else > (in recommended packages, or elsewhere). > > In the spatstat package we have been using a 'listof' > to represent a list of spatial objects of the same class > (such as point patterns, or pixel images) > and we've defined a plot method. > > Is it OK for us to hijack an existing class in this way, > or is this a violation of some future plans/ design feature of R ? > > We're about to publish a book on spatstat > so I would much appreciate advice if we need to change it. > > regards > Adrian > > Prof Adrian Baddeley FAA > University of Western Australia >