Too bad you didn't stick to your earlier intention:
> I'll leave it up to the developers to designate this as a bug or not, > but I would certainly prefer that new() and show() never reports errors > when an empty object is passed as an argument (of any class).
I agree, assuming what you mean by "empty" is the default object from the class. But the issue is one of the behavior of the R evaluator, which wants to evaluate the call object when it's passed to the default print() code--just as the error message says. We can maybe get around that, but I don't think your solution below is desirable. There is a reason that the default function reference is called "<undef>": an error _should_ be generated if you evaluate a call to an undefined function.
Notice: R> tt <- new("call") R> dput(tt) "<undef>"()
This works as a show() method, but the current default printing code in R never calls show() for objects of class "call" so something else would have to be done, in the base package or the evaluator, rather than in methods.
R> setMethod("show", "call", function(object)dput(object)) [1] "show" R> show(tt) "<undef>"() R> tt Error in print("<undef>"()) : couldn't find function "<undef>"
[EMAIL PROTECTED] wrote:
I have found a solution to the new("call") problem that I believe produces the correct behavior for the default call object, and am also reclassifying this as a bug, as I believe the current behavior to be incorrect.
Recap, the following error occurs:
new("call")
Error in print("<undef>"()) : couldn't find function "<undef>"
It looks like the problem is that the default object for new("call") is the function "<undef>"(), which does not exist. So, the show() and print() methods correspondingly fail.
If I initialize the "<undef>"() function at the beginning of my code to an empty function:
"<undef>" <- new("function")
then new("call") will then reference an existing (yet empty) object that is coerced into a call, and the show and print methods correctly display this object as NULL. Furthermore, I am able to extend this empty call object to other S4 objects without trouble.
Now:
"<undef>" <- new("function") new("call")
NULL
str(new("call"))
Formal class 'call' [package "methods"] with 0 slots list()
This, I believe is the preferred behavior of new("call"), and I would contend this fix should be included in the R source.
Best, Robert
-----Original Message-----
From: McGehee, Robert [mailto:[EMAIL PROTECTED] Sent: Saturday, January 08, 2005 6:06 PM
To: r-devel@stat.math.ethz.ch
Subject: [Rd] new("call") problem
The below looks like the show method has trouble with the default call object (or that there is no default call object). Not sure if this is a bug, design problem, or a difficulty on my part using and extending the call class, but it has caused difficulty for when I want to extend the call class into other S4 classes.
new("call")
Error in print("<undef>"()) : couldn't find function "<undef>"
This error pops up when I show an object with an empty call slot. Error in show("<undef>"()) : Unable to find the argument "object" in selecting a method for function "show"
I'll leave it up to the developers to designate this as a bug or not, but I would certainly prefer that new() and show() never reports errors when an empty object is passed as an argument (of any class).
Best, Robert
Robert McGehee Geode Capital Management, LLC 53 State Street, 5th Floor | Boston, MA | 02109 Tel: 617/392-8396 Fax:617/476-6389 mailto:[EMAIL PROTECTED]
This e-mail, and any attachments hereto, are intended for use by the addressee(s) only and may contain information that is (i) confidential information of Geode Capital Management, LLC and/or its affiliates, and/or (ii) proprietary information of Geode Capital Management, LLC and/or its affiliates. If you are not the intended recipient of this e-mail, or if you have otherwise received this e-mail in error, please immediately notify me by telephone (you may call collect), or by e-mail, and please permanently delete the original, any print outs and any copies of the foregoing. Any dissemination, distribution or copying of this e-mail is strictly prohibited.
______________________________________________ R-devel@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
______________________________________________ R-devel@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
______________________________________________ R-devel@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-devel