2

Specific to Mac -- simple reproducible example:

Sys.sleep(60)
print("output")

The help page for Sys.sleep() says that it should check for interrupts, but it doesn't seem to respect any form thereof, not ctrl-c, not Esc, not the stop button. You can use a ctrl-c interrupt running the script from the terminal, but that kills the entire script.

I'd like to have a set delay interval that I can still interrupt, at which point the script will continue (so, "output" would still print even if 60s had not yet elapsed). Is there a (hopefully not too resource-heavy) way to do this?

More generally, is there any way to interrupt a Sys.sleep call on a Mac when you're not in the terminal, regardless of what happens afterwards?

Relevant resources that still don't seem to address this:

How do I interrupt R?

https://cran.r-project.org/bin/macosx/RMacOSX-FAQ.html#How-can-I-interrupt-lengthy-operations-or-output_003f <-- Apparently can inject an interrupt from the terminal? But this is clunky and certainly doesn't get at the main goal.

Community
  • 1
  • 1
Joe
  • 119
  • 5
  • Try holding down the escape key. This just worked for me (though I'm currently on a windows machine). The help file says that `Sys.sleep` "wakes the process up often enough to respond to GUI events, typically every half second." So just pressing the key quickly once may not work. – lmo May 31 '16 at 16:28
  • Pressing Esc works for me just fine on a Mac, but I'm not really clear on what you expect to accomplish by calling `Sys.sleep` and then interrupting it. Do you mean to do something more like this: http://stackoverflow.com/q/15272916/324364 – joran May 31 '16 at 16:42
  • Esc on Mac OS 10.6.8 with R 3.2.1 did not work. – nya May 31 '16 at 17:18
  • Thanks. Imo, the help file seems inaccurate based on tests, which is why I was doing this. I'm trying to construct a repeating R script that popped up a dialogue box for data entry every so often, so I was using the sleep call to provide the delay. However, I'd love to be able to cancel the sleep behavior (which is documented as possible but non-functional), and even better I'd love to be able to interrupt operation while maintaining an orderly operation of the rest of the script. – Joe Jun 05 '16 at 20:32

1 Answers1

0

Here's one possibility I found, using the system sleep rather than the R version:

system("sleep 60")
print("output")

This allows the use of Esc on a Mac to exit the system sleep (while the R console remains in focus), so provides a workable solution.

Not exactly elegant, but perfectly serviceable.

(Flagging my own post, but if someone comes along with a better solution, they can have the check.)

Joe
  • 119
  • 5