[Rd] extending lattice to S4 classes
Prof Brian Ripley
ripley at stats.ox.ac.uk
Sat Oct 15 09:02:56 CEST 2005
I think you are confusing us: xyplot is an S3 generic with no 'data'
argument. It is xyplot.formula that you want to add dispatch on its
'data' argument. I don't really see why you want to mix S3 and S4
systems, but you could make xyplot.formula an S3 or S4 generic and
dispatch on 'data', just as you did earlier with xyplot.
Other xyplot methods need not (and probably do not) have a 'data'
argument.
On Fri, 14 Oct 2005, ernesto wrote:
> ernesto wrote:
>
>> Hi,
>>
>> I'm writing methods for a package called FLCore (see
>> http://flr-project.org/) in particular for a class called "FLQuant"
>> which extends array.
>>
>> Previously I was able to write methods based on the class of "data" but
>> now I can not do it due to the single parameter "x". Is there a way to
>> do this ?
> I found an hack (see below) to make it work but it's terrible and hugly
> ... some suggestions are welcome. It simply tests if data belongs to
> class "FLQuant" and transforms it into a data.frame before ploting.
>
> Regards
>
> EJ
>
> if (!isGeneric("xyplot")) {
> setGeneric("xyplot", useAsDefault = xyplot)
> }
>
>
> setMethod("xyplot", signature("formula"), function(x, ...){
>
> dots <- list(...)
> if(class(dots$data)=="FLQuant") dots$data <- as.data.frame(dots$data)
> call.list <- c(x = x, dots)
>
> # needed this to avoid an infinite loop because xyplot is defined only
> for "x"
> xyplot <- lattice::xyplot
> ans <- do.call("xyplot", call.list)
> ans$call <- match.call()
> ans
>
> })
--
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-devel
mailing list