[Rd] Error in "getClass" when calling the function "show"

Laurent Gautier lgautier at gmail.com
Tue Jun 10 09:58:17 CEST 2008


2008/6/10 Prof Brian Ripley <ripley at stats.ox.ac.uk>:
> On Tue, 10 Jun 2008, Laurent Gautier wrote:
>
>> 2008/6/10 Prof Brian Ripley <ripley at stats.ox.ac.uk>:
>>>
>>> showDefault has
>>>
>>>   clDef <- getClass(class(object))
>>>
>>> Looks like the showDefault code intended
>>>
>>>   clDef <- getClass(class(object), .force=TRUE)
>>>
>>> However, why are you calling show() on a non-S4 object?  I cannot see any
>>> advtanges in doing so.
>>
>> I'd like *one* printing method for all objects, and the generic "show"
>> is registered as working for ANYthing (see below) ?
>
> print() calls show() for S4 objects (with no additional arguments).
>
> I agree show() ought to do what it is documented to, but calling it on
> non-S4 objects is inefficient.

Fair enough.
May be that word of caution could appear in the documentation for "show" then ?

A good place could be where the documentation says:
The 'methods' package overrides the base definition of
'print.default' to arrange for automatic printing to honor methods
for the function 'show'.

which led me to think that "show" is covering more cases than "print" does
(while apparently the opposite is happening with "print" delegating to "show").



Thanks,



Laurent




>> Or is defining one's own function currently recommended ?
>>
>> myPrint <- function(x, ...)
>> {
>>  if (isS4(x)) {
>>   show(x, ...)
>>  } else {
>>   print(x, ...)
>>  }
>> }
>>
>>> showMethods("show")
>>
>> Function: show (package methods)
>> object="ANY"
>> object="classRepresentation"
>> object="derivedDefaultMethod"
>>   (inherited from: object="MethodDefinition")
>> object="function"
>>   (inherited from: object="ANY")
>> object="genericFunction"
>> object="MethodDefinition"
>> object="MethodsList"
>>   (inherited from: object="ANY")
>> object="MethodWithNext"
>> object="ObjectsWithPackage"
>> object="signature"
>> object="traceable"
>>
>>> showMethods("print")
>>
>> Function "print":
>> <not a generic function>
>>>
>>> getMethod("show", "ANY")
>>
>> Method Definition (Class "derivedDefaultMethod"):
>>
>> function (object)
>> showDefault(object, FALSE)
>> <environment: namespace:methods>
>>
>> Signatures:
>>       object
>> target  "ANY"
>> defined "ANY"
>>
>>
>>> On Tue, 10 Jun 2008, Laurent Gautier wrote:
>>>
>>>> Dear List,
>>>>
>>>> Calling "show" on an object of class "summary.lm" gives:
>>>> Error in getClass(class(object)) : "summary.lm" is not a defined class
>>>>
>>>> Is this a miss on my end ?
>>>>
>>>>
>>>>> x <- seq(1, 10)
>>>>> show(x)
>>>>
>>>> [1]  1  2  3  4  5  6  7  8  9 10
>>>>>
>>>>> y <- runif(10)
>>>>> fit <- lm(y ~ x)
>>>>> show(fit)
>>>>
>>>> Call:
>>>> lm(formula = y ~ x)
>>>>
>>>> Coefficients:
>>>> (Intercept)            x
>>>>  1.04938     -0.08869
>>>>
>>>>> show(summary(fit))
>>>>
>>>> Error in getClass(class(object)) : "summary.lm" is not a defined class
>>>>>
>>>>> class(summary(fit))
>>>>
>>>> [1] "summary.lm"
>>>>>
>>>>> class((fit))
>>>>
>>>> [1] "lm"
>>>>>
>>>>> getClass("lm")
>>>>
>>>> Virtual Class
>>>>
>>>> No Slots, prototype of class "S4"
>>>>
>>>> Extends: "oldClass"
>>>>
>>>> Known Subclasses:
>>>> Class "mlm", directly
>>>> Class "aov", directly
>>>> Class "glm", directly
>>>> Class "maov", by class "mlm", distance 2
>>>> Class "glm.null", by class "glm", distance 2
>>>>>
>>>>> getClass("summary.lm")
>>>>
>>>> Error in getClass("summary.lm") : "summary.lm" is not a defined class
>>>>>
>>>>> sessionInfo()
>>>>
>>>> R version 2.7.0 Patched (2008-06-07 r45877)
>>>> i686-pc-linux-gnu
>>>>
>>>> locale:
>>>>
>>>>
>>>> LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=C;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C
>>>>
>>>> attached base packages:
>>>> [1] stats     graphics  grDevices utils     datasets  methods   base
>>>>
>>>>
>>>> Laurent
>>>>
>>>> ______________________________________________
>>>> R-devel at r-project.org mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>>
>>>
>>> --
>>> Brian D. Ripley,                  ripley at stats.ox.ac.uk
>>> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
>>> University of Oxford,             Tel:  +44 1865 272861 (self)
>>> 1 South Parks Road,                     +44 1865 272866 (PA)
>>> Oxford OX1 3TG, UK                Fax:  +44 1865 272595
>>>
>>
>
> --
> Brian D. Ripley,                  ripley at stats.ox.ac.uk
> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
> University of Oxford,             Tel:  +44 1865 272861 (self)
> 1 South Parks Road,                     +44 1865 272866 (PA)
> Oxford OX1 3TG, UK                Fax:  +44 1865 272595
>



More information about the R-devel mailing list