[Rd] Simple class with an automatic printing issue
William Dunlap
wdunlap at tibco.com
Mon Apr 13 05:34:41 CEST 2009
It may have to do with the results of is.object():
> is.object(1*structure(1,class="testClass"))
[1] FALSE
> is.object(structure(1,class="testClass")*1)
[1] TRUE
> is.object(structure(1,class="testClass"))
[1] TRUE
is.object(x) should be true if x has a class attribute,
but 1*structute(1,class="testClass") makes a thing
with a class attribute but without the 'OBJECT' bit set.
Bill Dunlap
TIBCO Software Inc - Spotfire Division
wdunlap tibco.com
> -----Original Message-----
> From: r-devel-bounces at r-project.org
> [mailto:r-devel-bounces at r-project.org] On Behalf Of Tom Short
> Sent: Sunday, April 12, 2009 4:00 PM
> To: r-devel at r-project.org
> Subject: [Rd] Simple class with an automatic printing issue
>
> I don't understand the following behavior for a simple S3 class. The
> auto-printing at the command line
> doesn't behave as I expect. I'm probably missing something,
> but it might be
> a bug.
>
> > print.testClass <- function(x, ...) cat("Class:", class(x),
> ":", x, "\n")
>
> > structure(1, class = "testClass")
> Class: testClass : 1
>
> > print(1 * structure(1, class = "testClass"))
> Class: testClass : 1
>
> > 1 * structure(1, class = "testClass") # why doesn't
> auto-printing call
> print.testClass here?
> [1] 1
> attr(,"class")
> [1] "testClass"
>
> > structure(1, class = "testClass") * 1
> Class: testClass : 1
>
>
> platform i386-pc-mingw32
> arch i386
> os mingw32
> system i386, mingw32
> status RC
> major 2
> minor 9.0
> year 2009
> month 04
> day 10
> svn rev 48318
> language R
> version.string R version 2.9.0 RC (2009-04-10 r48318)
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
More information about the R-devel
mailing list