From sfalcon at fhcrc.org  Fri Apr 20 19:56:15 2007
From: sfalcon at fhcrc.org (Seth Falcon)
Date: Fri, 20 Apr 2007 10:56:15 -0700
Subject: [Rd] infinite recursion when printing former S4 objects
Message-ID: <m2ps5zlykg.fsf@ziti.local>

Hello all,

An S4 class that contains matrix can be converted into a matrix using
as().  When the resulting object is printed implicitly at the command
line, all is well.  When print() is explicitly called, I see an
infinite recursion.

Here is an example:

## create a subclass of matrix
    > setClass("Foo", representation(name="character"), contains="matrix")
    [1] "Foo"

## test it out
    > f <- new("Foo", name="Sam", matrix())
    > z <- as(f, "matrix")
    > z
         [,1]
    [1,]   NA
    > print(z)
    Error: evaluation nested too deeply: infinite recursion / options(expressions=)?

An easy cut/paste version is below.  I'm seeing this with an R 2.5.0
beta.  I noticed that isS4(z) returns TRUE.  This may or may not be
surprising, but seems quite related to the issue at hand.


+ seth



## ----------------8<--------------8<-----------------------

setClass("Foo", representation(name="character"), contains="matrix")
f <- new("Foo", name="Sam", matrix())
f
m <- as(f, "matrix")
m
print(m)

## ----------------8<--------------8<-----------------------


-- 
Seth Falcon | Computational Biology | Fred Hutchinson Cancer Research Center
http://bioconductor.org



[Rd] infinite recursion when printing former S4 objects
Seth Falcon