From wdunlap at tibco.com  Mon Apr 13 05:34:41 2009
From: wdunlap at tibco.com (William Dunlap)
Date: Sun, 12 Apr 2009 20:34:41 -0700
Subject: [Rd] Simple class with an automatic printing issue
In-Reply-To: <fd27013a0904121559hc3ccb30n83272819ca8f714a@mail.gmail.com>
References: <fd27013a0904121559hc3ccb30n83272819ca8f714a@mail.gmail.com>
Message-ID: <77EB52C6DD32BA4D87471DCD70C8D7000107590F@NA-PA-VBE03.na.tibco.com>

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
> 



[Rd] Simple class with an automatic printing issue
William Dunlap