5

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?

glenn jackman
  • 238,783
  • 38
  • 220
  • 352
isomorphismes
  • 8,233
  • 9
  • 59
  • 70
  • 1
    Check out `help(conditions)` – Rich Scriven Jan 14 '15 at 19:03
  • Thanks @RichardScriven ! Do you want to make that the answer so I can accept it? – isomorphismes Jan 14 '15 at 19:13
  • 2
    @RichScriven, I know it's been a couple of years, but ... `tryCatch` only seems to catch errors and warnings, not external signals (such as HUP, TERM). I cannot seem to make an R script recognize when it has been HUPed and stop gracefully. I believe there's a distinction between "unexpectedly stop" (some error condition) and "stopped by external influence" (such as SIGHUP). What am I missing in the docs? – r2evans Mar 14 '18 at 06:48

1 Answers1

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.

Rich Scriven
  • 97,041
  • 11
  • 181
  • 245