From sfalcon at fhcrc.org  Fri Mar  2 17:22:29 2007
From: sfalcon at fhcrc.org (Seth Falcon)
Date: Fri, 02 Mar 2007 08:22:29 -0800
Subject: [Rd] S3 best practice
In-Reply-To: <5D78FE68-7F9C-4605-84E5-B7B91EB0BDB5@soc.soton.ac.uk> (Robin
	Hankin's message of "Fri, 2 Mar 2007 14:01:59 +0000")
References: <5D78FE68-7F9C-4605-84E5-B7B91EB0BDB5@soc.soton.ac.uk>
Message-ID: <m28xefaa4a.fsf@ziti.local>

Robin Hankin <r.hankin at noc.soton.ac.uk> writes:

> Hello everyone
>
> Suppose I have an S3 class "dog" and a function plot.dog() which
> looks like this:
>
> plot.dog <- function(x,show.uncertainty, ...){
>      <do a simple plot>
>    if (show.uncertainty){
>    <perform complicated combinatorial stuff that takes 20 minutes
>        and superimpose the results on the simple plot>
>    }
> }

How uncertain is the dog in the window?

> I think that it would be better to somehow precalculate the
> uncertainty stuff and plot it separately.
>
> How best to do this
> in the context of an S3 method for plot()?

Doing long computations within plot functions can be annoying because
often one needs to "tweak" the visual style of a plot and this
requires numerous round trips.  So I like your idea of precomputing
the uncertainty stuff.

uncertainty.dog could return data that could then optionally be passed
into the plot method.  Another possibility is that the dog "class"
could store the uncertainty data and then the plot method would plot
it if it is there (and/or if an option to plot is given).  In this
case, I guess it would be:  x <- addUncertainty(x)

+ seth



[Rd] S3 best practice
Seth Falcon