Question

I'm considering using recover() as an error option. but every time I hit an error, I am unable to do any interactive debugging because it just keeps telling me Enter a frame number, or 0 to exit no matter what I do (I have commented in full everything that I type after the error occurs):

> options(error = recover)
> foo <- function() {x <- "foo"; stop(x)}
> foo()
Error in foo() : foo

Enter a frame number, or 0 to exit   

1: foo()

### I type '1'
Selection: 1
Called from: top level 
Browse[1]> 

Enter a frame number, or 0 to exit   

1: foo()

### I type 'x'
Selection: x
Enter an item from the menu, or 0 to exit

### I type 'objects()'
Selection: objects()
Enter an item from the menu, or 0 to exit

### I type '0'
Selection: 0

### Recover exits and R returns to normal

The only thing it responds to appears to be '0' to exit recover(). Note that I did not press enter at Browse[1]> - it is simply skipped over and I don't get the chance to input anything.

What am I doing wrong?

I'm using R version 3.0.2 (2013-09-25) with Revolution R Enterprise IDE (x64) 7.0.0 under Windows 8.1

Edit

I think this is a problem to do with Revolution R IDE, as I tried this with the default RGui console and I could type stuff at Browse[1]> and therefore use recover successfully. If anyone with experience of Revolution R IDE has any further insight on this, I'd be most grateful.

Was it helpful?

Solution 2

I've submitted a bug report to Revolution Analytics, and so far this has been their reply:

Milo,

Thanks for the report. As I indicated, a defect has been filed with the development team. Running this code through the console works as expected and that only through the script window does it fail. I am closing the support ticket as there is no decision when this will be address.

Regards,

Brian Pinkney

Manager, Revolution Analytics Technical Support

I will update if they contact me again.

OTHER TIPS

When you say options(error = recover) you are stopping everything to have access to the entire call stack. If you had a function that would have a longer rout, this would be more apparent. In your case, when you enter 1, you go into the function foo at the time of evaluation. This function holds an object called x with the values of "foo" as demonstrated below.

> foo()
Error in foo() : foo

Enter a frame number, or 0 to exit   

1: foo()

Selection: 1
Called from: top level 
Browse[1]> ls()
[1] "x"
Browse[1]> x
[1] "foo"

If you're done browsing in the current call (in your case under number 1), you can exit to the "menu" by pressing enter or calling c (see ?browser).

EDIT

Here's a bit longer example that may show you what recover does (basically a menu giving you access to called functions and their objects).

> foo <- function(x) {
+   obj1 <- "object in foo"
+   foo2 <- function(y) {
+     obj2 <- "object in foo2"
+     stop()
+   }
+   foo2(x)
+ }
> 
> foo(letters)
Error in foo2(x) : 

Enter a frame number, or 0 to exit   

1: foo(letters)
2: #7: foo2(x)

Selection: 1 # go into function foo()
Called from: top level 
Browse[1]> ls()
[1] "foo2" "obj1" "x"   
Browse[1]> obj1
[1] "object in foo"
Browse[1]>  # i hit enter here

Enter a frame number, or 0 to exit   

1: foo(letters)
2: #7: foo2(x)

Selection: 2 # go into function foo2()
Called from: foo(letters)
Browse[1]> ls()
[1] "obj2" "y"   
Browse[1]> obj2
[1] "object in foo2"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top