[R] S4 classes and debugging - Is there a summary?
Martin Morgan
mtmorgan at fhcrc.org
Fri Jul 2 16:01:54 CEST 2010
On 07/02/2010 05:05 AM, Joris Meys wrote:
> Dear all,
>
> I'm getting more and more frustrated with the whole S4 thing and I'm
> looking for a more advanced summary on how to deal with them. Often I
> get error messages that don't make sense at all, or the code is not
> doing what I think it would do. Far too often inspecting the code
> requires me to go to the source, which doesn't really help in easily
> finding the bit of code you're interested in.
>
> Getting the code with getAnywhere() doesn't always work. Debug()
> doesn't work. Using trace() and browser() is not an option, as I can't
> find the correct method.
>
> eg :
> library(raster)
>> getAnywhere(xyValues)
> A single object matching ‘xyValues’ was found
> It was found in the following places
> package:raster
> namespace:raster
> with value
>
> standardGeneric for "xyValues" defined from package "raster"
>
> function (object, xy, ...)
> standardGeneric("xyValues")
> <environment: 0x04daf14c>
> Methods may be defined for arguments: object, xy
> Use showMethods("xyValues") for currently available ones.
>> showMethods("xyValues")
> Function: xyValues (package raster)
> object="Raster", xy="data.frame"
> object="Raster", xy="SpatialPoints"
> object="Raster", xy="vector"
> object="RasterLayer", xy="matrix"
> object="RasterStackBrick", xy="matrix"
>
> And now...?
selectMethod(xyValues, c('RasterLayer', 'matrix'))
would be my choice.
> Is there an overview that actually explains how you get the
> information you're looking for without strolling through the complete
> source? Sorry if I sound frustrated, but this is costing me huge
> amounts of time, to that extent that I rather write a custom function
> than use one in an S4 package if I'm not absolutely sure about what it
> does and how it achieves it.
I don't really have the right experience, but Chamber's 2008 Software
for Data Analysis... and Gentleman's 2008 R Programming for
Bioinformatics... books would be where I'd start. ?Methods and ?Classes
are I think under-used.
Martin
>
> Cheers
> Joris
>
>
--
Martin Morgan
Computational Biology / Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109
Location: Arnold Building M1 B861
Phone: (206) 667-2793
More information about the R-help
mailing list