R-alpha: print.noquote --- Wierd method / class dispatching --- ???

Martin Maechler (maechler@stat.math.ethz.ch)
Fri, 13 Dec 96 17:27:22 +0100


Date: Fri, 13 Dec 96 17:27:22 +0100
Message-Id: <9612131627.AA14844@>
From: Martin Maechler <maechler@stat.math.ethz.ch>
To: R-testers@stat.math.ethz.ch
Subject: R-alpha: print.noquote --- Wierd  method / class  dispatching --- ???

Here are several problems (in one nice "R file"):

I did n't have time to find out exactly what's going on :
 
---------- snip snip


## A nice idea of using  OO programming , but BADLY implemented
print.noquote <- function(obj,...) print(obj, quote = F, ...)

x <- paste(1:10) ; class(x) <- "noquote"

print.default(unclass(x), quote = F)
##>
x #-- should give EXACTLY the same (for this x):   >>>>>>> BUT ! <<<<<

##>> Error: memory exhausted
#           ----------------  (infinite loop....)
##>> Process S2 segmentation violation ...


###--- But, this should be the solution:

print.noquote <- function(obj,...) NextMethod("print",obj, quote = F, ...)

print.default(x)
##-  [1] "1"  "2"  "3"  "4"  "5"  "6"  "7"  "8"  "9"  "10"
##- attr(,"class")
##- [1] "noquote"
x #-- BUT gives the same !!!


###--- This one:  Fails too :

print.noquote <- function(obj,...) {
  if(is.object(obj)) class(obj) <- class(obj)[class(obj) != "noquote"]
  NextMethod("print",obj, quote = F, ...)
}

x <- paste(1:10) ; class(x) <- "noquote"
x ##>>> Error: match requires vector arguments

## Now, watch this :
print.noquote(x) ##-- get the same error as above...
# BUT:
x
##> [1] "1"  "2"  "3"  "4"  "5"  "6"  "7"  "8"  "9"  "10"

##>>>>> I.e.  'x'   LOST it's class attribute !!!!



Martin Maechler <maechler@stat.math.ethz.ch>		 <><
Seminar fuer Statistik, SOL F5
ETH (Federal Inst. Technology)	8092 Zurich	 SWITZERLAND
phone: x-41-1-632-3408		fax: ...-1086
http://www.stat.math.ethz.ch/~maechler/
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-testers mailing list -- For info or help, send "info" or "help",
To [un]subscribe, send "[un]subscribe"
(in the "body", not the subject !)  To: r-testers-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-