-->

Can I trap signals in R?

2019-02-18 09:30发布

问题:

In bash I can trap SIGINT, SIGKILL, SIGTERM, and so on. That allows me to do different things depending how the program was unexpectedly stopped.

Is there a way to do this in R?

回答1:

Expanding a bit on my comment which OP asked me to post as an answer


The help file for conditions has the description

These functions provide a mechanism for handling unusual conditions, including errors and warnings.

There are many handling functions explained in the file, with examples. So I suggest starting with

help(conditions)
## and
example(conditions)

Additionally, tools::assertCondition might be worth a look too. It is linked at the bottom of the conditions documentation.