[Rd] extending lattice to S4 classes

ernesto ernesto at ipimar.pt
Tue Oct 18 12:50:48 CEST 2005


Prof Brian Ripley wrote:

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

Hi,

Sorry to get back to this problem so late.

I want to use lattice plots for an array. In this specific case this
array is of class FLQuant which is defined by package FLCore.

This array has 5 dimensions age, year, unit, season and area. My aim is
to use formula to define what to plot and what to condition on. So
procedures like used for barchart.table are not usefull for me because
the user loses the option of defining the model to plot.

With the previous version of lattice I was able to use formula and data
to dispatch. So I defined S4 generic methods for most high level methods
(bwplot, stripplot, dotplot, xyplot, histogram, etc) and simply
transform FLQuant objects into dataframes that were passed to the
lattice methods. No harm done to other data objects.

With the new version only one object is available for dispatching "x" so
if I define some xyplot.FLQuant I will miss the formula argument.

My question is if there is a way of doing this or not.

Best regards

EJ



More information about the R-devel mailing list