Opened 13 years ago
Last modified 8 years ago
#7681 new defect
R pexpect interface doesn't handle errors well
Reported by: | kcrisman | Owned by: | was |
---|---|---|---|
Priority: | major | Milestone: | sage-6.4 |
Component: | interfaces | Keywords: | pexpect, interface, R, r-project |
Cc: | schilly | Merged in: | |
Authors: | Reviewers: | ||
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description
For instance:
sage: r.length([1,2,3,4]) [1] 4 sage: r.vector('c(1,2,3,4,3)') [1] 4 sage: r.length([1,2,3,4]) [1] 4 sage: r.vector('c(1,2,3,4,3)') [1] 4 sage: r.vector('c(1,2,3,4,3)') [1] 2 sage: r.vector('c(1,2,3,4,3)') [1] 1 2 3 4 3 sage: r.vector('c(1,2,3,4,3)') [1] 1 2 3 4 3 sage: r.vector('c(1,2,3,4,3)') Error: object 'sage49' not found
Somehow the R interface is keeping stuff from previous calls and returning it, and then at some point choking. Incidentally, in the above session, after trying many other R commands this way and always getting similar errors, all of a sudden
[1] 1 2 3 4 3
showed up - as the answer to something else! Where it had been hiding, I can only guess.
Change History (12)
comment:1 Changed 13 years ago by
comment:2 Changed 13 years ago by
Okay, now I understand this example. But clearly the error should be shown, correct? The current behavior is bizarre, and in general this sort of thing happens a lot when trying to use it.
Should we not use the R interface and use rpy2 instead? But it looks rather more difficult to use, upon a quick perusal of the documentation.
comment:3 Changed 13 years ago by
And here's just something randomly annoying:
sage: r([1,1/2,1/2]) [1] 1.0 0.5 0.5 sage: r([0,sqrt(3)/2,sqrt(3)/2]) Error: object 'sage10' not found
Even though R knows what sqrt(3) is natively:
> sqrt(3)/2 [1] 0.8660254
I'm not saying this is really related to the summary of the ticket, but it's not unrelated, either.
comment:4 Changed 13 years ago by
yes of course, wrong error handling + hickup is bad. these examples might be useful to track down the bug.
http://rpy.sourceforge.net/rpy2/doc/html/rpy_classic.html might be helpful when using rpy, though...
comment:5 Changed 12 years ago by
- Summary changed from R pexpect interface seems to keep data around to R pexpect interface doesn't handle errors well
Changing summary to be more accurate - hopefully fixing this will fix the issues reported.
comment:6 Changed 12 years ago by
Okay, the problem is that instead of handling errors, we are ignoring them:
# don't abort on errors, just raise them! # necessary for non-interactive execution self.eval('options(error = expression(NULL))')
But see here - it turns out that this is R's way of just totally ignoring them, not just 'raising' them. This should be fixed.
comment:7 Changed 12 years ago by
- Component changed from packages to interfaces
- Owner changed from tbd to was
comment:8 Changed 10 years ago by
- Keywords r-project added
comment:9 Changed 9 years ago by
- Milestone changed from sage-5.11 to sage-5.12
comment:10 Changed 9 years ago by
- Milestone changed from sage-6.1 to sage-6.2
comment:11 Changed 8 years ago by
- Milestone changed from sage-6.2 to sage-6.3
comment:12 Changed 8 years ago by
- Milestone changed from sage-6.3 to sage-6.4
This interface to R (which is entirely different from the rpy2 python module) is rather hard to do and still needs work. I think the problem is that "vector" in R does something differently than you imagine. I.e. an error happens which isn't shown and the pexpect interface is confused.
works for me.
Here what really happens in R: