couldn't find function "print.tframe"

Peter Dalgaard BSA p.dalgaard@biostat.ku.dk
17 May 1998 12:08:18 +0200


Thomas Lumley <thomas@biostat.washington.edu> writes:

> 
> 
> Ok. The print.tframe problem appears to be as follows:
> 
> When printList has a list element that is an object it creates a call to
> print() with the evaluated object and evaluates that call in the
> environment R_NilValue (ie NULL).
> 
> If this object has class "foo" print.foo() is called. If there is a 
> NextMethod() in print.foo, do_nextmethod  reaches back to find
> the environment that print() was called from and looks for the
> definition of print.foo() that applies there, in order to get the formal
> arguments right.  This fails, since print() was 'called' from the NULL
> environment, where print.foo() is not defined.
> 
> You can reproduce this in interpreted code by
> R> b<-1              
> R> class(b)<-"foo" 
> R> print.foo<-function(x){cat("foo\n");NextMethod()}
> R> eval(expression(print(structure(1,class="foo"))),NULL)

Hmmmm....

Here's another aspect of the problem:

I tried creating a new print function with a call to sys.status
inserted befor the UseMethod, after previously doing a debug(print),
and:

>  eval(expression(print(structure(1,class="foo"))),NULL)
debugging in: print(structure(1, class = "foo"))
foo
Error: couldn't find function "print.foo"

So it is still calling the old print (in package:base). The new one
would have debugging turned off for one thing. (BTW: Why doesn't the
debugger stop and wait for input before doing the UseMethod call?)

In contrast,
> b
$sys.calls
$sys.calls[[1]]
print(structure(1, class = "foo"))

<...etc...>
foo
[1] 1
attr(,"class")
[1] "foo"


-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._