[Rd] extending lattice to S4 classes

ernesto ernesto at ipimar.pt
Fri Oct 14 18:11:46 CEST 2005


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

})



More information about the R-devel mailing list