It is very wierd... Can some of you confirm the following behavior ?
It is a new bug (feature ?) which was not yet in 0.49 ...
noquote <- function(obj) {
## constructor for a useful "minor" class
if(!inherits(obj,"noquote")) class(obj) <- c(class(obj),"noquote")
obj
}
"[.noquote" <- function (x, subs) structure(unclass(x)[subs], class = "noquote")
print.noquote <- function(obj,...) {
## method for (character) objects of class 'noquote'
cl <- class(obj)
class(obj) <- cl[cl != "noquote"]
NextMethod("print", obj, quote = FALSE, ...)
}
nq <- noquote(letters)
##-- the next two should be equivalent, but are not ...?..
print(nq)
nq
print(nq)
[1] a b c d e f g h i j k l m n o p q r s t u v w x y z
nq
Error: couldn't find function "print.noquote"
unclass(nq)
[1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s"
[20] "t" "u" "v" "w" "x" "y" "z"
nq
Error: couldn't find function "print.noquote"
ls()
[1] "[.noquote" "noquote" "nq" "print.noquote"
print.noquote
function (obj, ...)
{
## method for (character) objects of class 'noquote'
cl <- class(obj)
class(obj) <- cl[cl != "noquote"]
NextMethod("print", obj, quote = FALSE, ...)
}
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
It is very wierd... Can some of you confirm the following behavior ?
It is a new bug (feature ?) which was not yet in 0.49 ...
I'm not sure that you can expect NextMethod to work if you fiddle with the
class list...
However, there is still something wrong with method dispatching, since
print.noquote <- function (obj, ...) NextMethod(quote = FALSE,...)
doesn't work either. The error occurs when R tries for some reason to
make a recursive call to print.noquote.
Using debug() also shows the interesting fact that
R> nq
calls print() with its arguments evaluated
------
debugging in: print(structure(c("a", "b", "c", "d", "e", "f", "g", "h",
"i",
"j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
"w", "x", "y", "z"), class = "noquote"))
debugging in: print.noquote(structure(c("a", "b", "c", "d", "e", "f", "g",
"h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t",
"u", "v", "w", "x", "y", "z"), class = "noquote"))
Error: couldn't find function "print.noquote"
-------
but
----------
R> print(nq)
print(nq)
debugging in: print(nq)
debugging in: print.noquote(nq)
[1] a b c d e f g h i j k l m n o p q r s t u v w x y z
attr(,"class")
[1] noquote
exiting from: print.noquote(nq)
exiting from: print(nq)
----------
doesn't evaluate the argument first.
Thomas Lumley
------------------------------------------------------+------
Biostatistics : "Never attribute to malice what :
Uni of Washington : can be adequately explained by :
Box 357232 : incompetence" - Hanlon's Razor :
Seattle WA 98195-7232 : :
------------------------------------------------------------
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-