s-news
[Top] [All Lists]

Summary: Re: any way of implementing nested try()'s?

To: s-news@lists.biostat.wustl.edu
Subject: Summary: Re: any way of implementing nested try()'s?
From: Tony Plate <tplate@blackmesacapital.com>
Date: Thu, 11 Dec 2003 09:23:10 -0700
In-reply-to: <5.2.1.1.2.20031205162322.04138558@mailhost.blackmesacapita l.com>
Summary: one person, who wished to remain anonymous, responded that they had had some problems that were probably related. This was in October 2003, and at the time Insightful support knew of no outstanding issues with the try() function.

I should have originally mentioned that I did report this bug to Insightful tech support, whose response was:

> You are expecting the right thing of the try() function. The problem is that
> there is a bug that try() doesn't nest properly.  This is why you don't get
> the expected output with your final case.  We have added your example
> to the bug report. This bug unfortunately won't be fixed in the next version, > S-PLUS 6.2, but we will look into fixing it for future versions. I will let you
> know if I become aware of a workaround.

One pretty obvious and not particularly elegant workaround in a batch file is to rely on the fact that the top-level continues regardless of errors, and change this code:

f2 <- function(real.stop=F, fake.stop=F) {
    cat("In f2()\n")
    if (fake.stop) try(stop("f2 fakes a stop"))
    if (real.stop) stop("f2 really stops!")
}
{try(f2(T,T)); cat("Continuing after f2()\n")}

to:

f2 <- function(real.stop=F, fake.stop=F) {
    cat("In f2()\n")
    if (fake.stop) try(stop("f2 fakes a stop"))
    if (real.stop) stop("f2 really stops!")
    return(T)
}

res <- F
res <- try(f2(T,T))
if (is(res, "Error") || identical(res, F))
    cat("There was an error in f2()\n")
cat("Continuing after f2()\n")}

-- Tony Plate

At Friday 04:28 PM 12/5/2003 -0700, I wrote:
I've been having some problems with nested try()'s (S-plus 6.1 under Windows 2000). Is anyone aware of a workaround? (Other than using R, which does not have this problem.) I guess the problem is actually with restart, but I haven't investigated that.

Here's some code that reproduces the problem.

f2 <- function(real.stop=F, fake.stop=F) {
    cat("In f2()\n")
    if (fake.stop) try(stop("f2 fakes a stop"))
    if (real.stop) stop("f2 really stops!")
}
{try(f2(F,F)); cat("Continuing after f2()\n")}
{try(f2(F,T)); cat("Continuing after f2()\n")}
{try(f2(T,F)); cat("Continuing after f2()\n")}
{try(f2(T,T)); cat("Continuing after f2()\n")}

In all cases, the expression in braces *should* complete successfully and print the message "Continuing after f2()", but in the last case it does not.

-- Tony Plate

--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu.  To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message:  unsubscribe s-news


<Prev in Thread] Current Thread [Next in Thread>
  • Summary: Re: any way of implementing nested try()'s?, Tony Plate <=