From thomas@biostat.washington.edu  Sun May 17 21:26:25 1998
From: thomas@biostat.washington.edu (Thomas Lumley)
Date: Sun, 17 May 1998 13:26:25 -0700 (PDT)
Subject: couldn't find function "print.tframe"
In-Reply-To: <x2wwblryzx.fsf@blueberry.kubism.ku.dk>
Message-ID: <Pine.SOL.3.95.980517132310.4388A-100000@gorn>

On 17 May 1998, Peter Dalgaard BSA wrote:

> 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?)

This is for the same reason.  In environment NULL you still have access to
the system environment but not to the global environment.  Look at
	eval(expression(print),NULL)
to see that it is indeed using the old version.  Fixing the environment
would fix this too.

I think the debugger doesn't stop and wait because it has problems with
functions that don't have braces {} enclosing them.

	-thomas


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


couldn't find function "print.tframe"
Thomas Lumley