Re: [Rd] methods and try() [R-devel]

From: Byron Ellis <byron.ellis_at_gmail.com>
Date: Thu, 16 Aug 2007 16:10:14 -0700

On 8/16/07, Luke Tierney <luke_at_stat.uiowa.edu> wrote:
> I think I understand the issue. The methods code uses R_tryCatch
> internally in a few places, hoping I think for a C level variant of
> tryCatch. It isn't meant to be used that way. It is intended only
> for use in embedded contexts where there is no proper top level, or
> possibly in contexts where conceptually the evaluation is happening in
> a seperate thread of execution. In particular R_tryEval establishes
> it's own top level (and that is the top level that is being jumped
> to):
>
> > { try(glue("A",B)); 2}
> Error: no function to return from, jumping to top level
> Error in glue("A", B) :
> error in evaluating the argument 'b' in selecting a method for function 'glue'
> [1] 2
> >
>
> Because of the "internal" top level established by R_tryEval there is
> no way to jump from inside the eval to an outer context, which is what
> needs to happen for try() to work here.
>
> It looks like the intent in methods_list_dispatch.c in all but one
> case is to catch the error and report something a bit more meaningful;
> in the one other case, in R_nextMethodCall, there is also a cleanup
> action that occurs before resignaling the error.

Yes, there seems to be some new (and much appreciated) error reporting that goes on in recent versions of R-devel that gives a stack trace of method calls instead of telling us that ".local" has failed, which was less useful.

>
> To fix this will I think require designing a C level tryCatch. That
> will take a bit of time to get right. Not sure if it will get done by
> 2.6.0. There may be a quick temporary fix but I'm not seeing one at
> this point.
>
> Arguably R_tryEval in its present form should also ensure that the
> handler stacks are empty in the call (not an issue for the intended
> embedded usage). Need to think about that a bit as well.

Ah, that's unfortunate. I guess I will have to back out that feature for the time being.

>
> Best,
>
> luke
>
> On Thu, 16 Aug 2007, Byron Ellis wrote:
>
> > On 8/16/07, Luke Tierney <luke_at_stat.uiowa.edu> wrote:
> >>
> >> There sae, at 2.5.0 I believe. At that point try was reimplemented in
> >> terms of tryCatch. That may have uncovered a bug in our code or
> >> yours, but without a reproducible example it's hard to say more.
> >
> > An indeed, I believe I've got one. Turns out it didn't solve my
> > problem though. So, imagine we have a method (with a new generic).
> > Say,
> >
> > setGeneric("glue",function(a,b) standardGeneric("glue"))
> > setMethod("glue",signature("character","character"),function(a,b) {
> > paste(a,b,sep="")
> > })
> >
> > Trying the code:
> >
> >> glue("A","B")
> > [1] "AB"
> >> glue("A",B)
> > Error: object "B" not found
> > Error in glue("A", B) :
> > error in evaluating the argument 'b' in selecting a method for function 'glue'
> >
> > Good. Works as expected (there's no B in the environment). However,
> > I'd expect try to work...
> >
> >> try(glue("A",B))
> > Error: no function to return from, jumping to top level
> > Error in glue("A", B) :
> > error in evaluating the argument 'b' in selecting a method for function 'glue'
> >
> > with silent=TRUE the "jumping to top level" is not caught and causes
> > scripts to bail out.
> >
> > Hopefully that helps?
> >
> >
> >>
> >> Best,
> >>
> >> luke
> >>
> >>
> >>>
> >>>>
> >>>> Best,
> >>>>
> >>>> luke
> >>>>
> >>>>
> >>>> --
> >>>> Luke Tierney
> >>>> Chair, Statistics and Actuarial Science
> >>>> Ralph E. Wareham Professor of Mathematical Sciences
> >>>> University of Iowa Phone: 319-335-3386
> >>>> Department of Statistics and Fax: 319-335-3017
> >>>> Actuarial Science
> >>>> 241 Schaeffer Hall email: luke_at_stat.uiowa.edu
> >>>> Iowa City, IA 52242 WWW: http://www.stat.uiowa.edu
> >>>>
> >>>
> >>>
> >>>
> >>
> >> --
> >> Luke Tierney
> >> Chair, Statistics and Actuarial Science
> >> Ralph E. Wareham Professor of Mathematical Sciences
> >> University of Iowa Phone: 319-335-3386
> >> Department of Statistics and Fax: 319-335-3017
> >> Actuarial Science
> >> 241 Schaeffer Hall email: luke_at_stat.uiowa.edu
> >> Iowa City, IA 52242 WWW: http://www.stat.uiowa.edu
> >>
> >
> >
> >
>
> --
> Luke Tierney
> Chair, Statistics and Actuarial Science
> Ralph E. Wareham Professor of Mathematical Sciences
> University of Iowa Phone: 319-335-3386
> Department of Statistics and Fax: 319-335-3017
> Actuarial Science
> 241 Schaeffer Hall email: luke_at_stat.uiowa.edu
> Iowa City, IA 52242 WWW: http://www.stat.uiowa.edu
>

-- 
Byron Ellis (byron.ellis_at_gmail.com)
"Oook" -- The Librarian

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Thu 16 Aug 2007 - 23:15:26 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 18 Aug 2007 - 11:38:47 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.