22 May 22:31
Capturing signals from within external libs
Jeffrey Ryan <jeff.a.ryan <at> gmail.com>
2012-05-22 20:31:07 GMT
2012-05-22 20:31:07 GMT
I have a continuous loop running in an external library that I am calling
from C (R API). This loop is processing events in real time with the
possibility of significant lag between events.
When processing an event, I can make use of R_CheckUserInterrupt, but
while the external library code is waiting on a new event, I don't have an
opportunity to call this - my entry points are only on events.
I can capture a SIGINT by redefining signal(SIGINT, myhandler) before
calling the lib, but I am somewhat at a loss in terms of what I can do
within the handler that would let me pass control back to R.
void myhandler (int s) {
error("interrupt caught!");
}
Works, but I am sure it isn't supposed to. In fact I know it is wrong,
since after interrupting once SIGINTs are subsequently ignored, even if I
reset the signal to the original one (as returned by the first call to
signal).
Currently I can exit(1) of course, but that is tragically bad form IMO,
though will work in my situation.
In short, what is the proper way to handle SIGINT in external code that is
called from R, that allows R to handle the signal. Thoughts or
suggestions appreciated.
Thanks,
Jeff
(Continue reading)
I'm thinking about ways to add more effective error
surveillance.
Your suggestion was not horribly complex and I'll look into it
further. My first foray failed because what I want (I think) is the
environment that they had when the first ">" came up. I tried baseenv
in a spot, but then my code couldn't find the model.frame function.
Terry T.
On 05/17/2012 05:00 AM, Duncan wrote:
> On 12-05-16 4:59 PM, Terry Therneau wrote:
>> > I've been tracking down a survival problem from R-help today. A short
>> > version of the primary issue is reconstructed by the following simple
>> > example:
>> >
>> > library(survival)
>> > attach(lung)
>> > fit<- coxph(Surv(time, status) ~ log(age))
>> > predict(fit, newdata=data.frame(abe=45))
>> >
>> > Note the typo in the last line of "abe" instead of "age". Instead of an
>> > error message, this returns predictions for all the subjects since
>> > model.frame matches "age" by searching more widely. I'd prefer the error.
>> > I suspect this is hard -- I'd like it to not see the attached lung data
>> > set, but still be able to find the log function.
>> > Is there a not-horribly-complex solution?
> The best solution is to not use attach(), use data=lung in the fit.
RSS Feed