From vogranovich at jumptrading.com  Fri Oct 15 20:45:11 2010
From: vogranovich at jumptrading.com (Vadim Ogranovich)
Date: Fri, 15 Oct 2010 13:45:11 -0500
Subject: [Rd] calling browser on error
In-Reply-To: <AANLkTinuY+RkavSeKW9OFmysmAK9ey8APViPT8X5K2r4@mail.gmail.com>
References: <25C02255A75A684A9CF77F7D663B438F95180C77@chiexchange02.w2k.jumptrading.com>
	<AANLkTinuY+RkavSeKW9OFmysmAK9ey8APViPT8X5K2r4@mail.gmail.com>
Message-ID: <25C02255A75A684A9CF77F7D663B438F95180C78@chiexchange02.w2k.jumptrading.com>

Joshua,

I didn't know about 'recover', thank you!

Anyway it doesn't work for me:
> tryCatch((function() { x <- 1; stop('ok') })(), error=recover())

Enter a frame number, or 0 to exit

1: tryCatch((function() {

Selection: 1
Called from: eval(expr, envir, enclos)
Browse[1]> x
Error: object 'x' not found
Browse[1]> Q

Though it does work if I set options(error = recover):
> options(error = recover)
> (function() { x <- 1; stop('ok') })()
Error in (function() { : ok

Enter a frame number, or 0 to exit

1: (function() {

Selection: 1
Called from: eval(expr, envir, enclos)
Browse[1]> x
[1] 1
Browse[1]> Q

I do not run the latest R so it might be the reason:
> version
               _
platform       i386-pc-mingw32
arch           i386
os             mingw32
system         i386, mingw32
status
major          2
minor          9.1
year           2009
month          06
day            26
svn rev        48839
language       R
version.string R version 2.9.1 (2009-06-26)


-----Original Message-----
From: Joshua Ulrich [mailto:josh.m.ulrich at gmail.com]
Sent: Friday, October 15, 2010 1:31 PM
To: Vadim Ogranovich
Cc: r-devel at r-project.org
Subject: Re: [Rd] calling browser on error

I believe options(error=recover) will do what you want.

--
Joshua Ulrich  |  FOSS Trading: www.fosstrading.com



On Fri, Oct 15, 2010 at 1:27 PM, Vadim Ogranovich
<vogranovich at jumptrading.com> wrote:
> Dear R-developers,
>
> I am trying to figure out a way to call browser() when an error occur, and naturally I want the browser() to be called in the environment of the error.
>
> I tried something simple in vain:
>
>> f <- function() { x <- 1; stop('ok') }
>> tryCatch(f(), error=browser())
> Called from: tryCatch(f(), error = browser())
> ## if browser() was called in the local environment of f then 'x' would be set, but it's not
> Browse[1]> x
> Error: object 'x' not found
> Browse[1]> Q
>
> Is there a way to make it work? What do people do to 'set an on-error breakpoint'?
>
> Thanks,
> Vadim
>
>
> Note: This email is for the confidential use of the named addressee(s) only and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you are hereby notified that any review, dissemination or copying of this email is strictly prohibited, and to please notify the sender immediately and destroy this email and any attachments.  Email transmission cannot be guaranteed to be secure or error-free.  Jump Trading, therefore, does not make any guarantees as to the completeness or accuracy of this email or any attachments.  This email is for informational purposes only and does not constitute a recommendation, offer, request or solicitation of any kind to buy, sell, subscribe, redeem or perform any type of transaction of a financial product.
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

Note: This email is for the confidential use of the named addressee(s) only and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you are hereby notified that any review, dissemination or copying of this email is strictly prohibited, and to please notify the sender immediately and destroy this email and any attachments.  Email transmission cannot be guaranteed to be secure or error-free.  Jump Trading, therefore, does not make any guarantees as to the completeness or accuracy of this email or any attachments.  This email is for informational purposes only and does not constitute a recommendation, offer, request or solicitation of any kind to buy, sell, subscribe, redeem or perform any type of transaction of a financial product.



[Rd] calling browser on error
Vadim Ogranovich