From ernesto at ipimar.pt  Fri Oct 14 18:11:46 2005
From: ernesto at ipimar.pt (ernesto)
Date: Fri, 14 Oct 2005 17:11:46 +0100
Subject: [Rd] extending lattice to S4 classes
In-Reply-To: <434F88B9.1020600@ipimar.pt>
References: <434F88B9.1020600@ipimar.pt>
Message-ID: <434FD8C2.205@ipimar.pt>

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 ?
>
>Regards
>
>EJ
>
>______________________________________________
>R-devel at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-devel
>  
>

Hi,

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

})



[Rd] extending lattice to S4 classes
ernesto