Evgeny Metelkin
2025-11-28

When R runs something heavy for an hour or two, laptops don't always care - many will still go to sleep if there's no user activity.
On Windows with Modern Standby, on macOS with default power settings, or on Linux with aggressive power-saving policies, this can interrupt work even if R is still busy.
NoSleepR solves this problem with a simple idea:
keep the system awake only while R is doing something important, and let it return to normal afterward.
It uses the operating system's official sleep-prevention mechanisms:
caffeinatesystemd-inhibitNo hacks, no fake mouse movement, and no permanent power-plan changes.
Install from CRAN:
install.packages("NoSleepR")
library(NoSleepR)
Turn sleep prevention on manually:
nosleep_on()
# long-running R work here
nosleep_off()
Or wrap a block:
with_nosleep({
# heavy computation here
})
If needed, keep the screen awake too:
with_nosleep(keep_display = TRUE, {
# long-running code
})
This is particularly useful on Windows laptops that ignore sleep-prevention when the display turns off in battery mode.
Disabling sleep mode globally works, but it's overkill:
NoSleepR keeps things simple: only stay awake when the code runs.
If your workflow calls C++, Rcpp, external binaries, or other blocking system calls, they are covered as long as R waits for them to finish.
Some behaviors are controlled strictly by the OS and cannot be overridden:
On remote servers, the package does nothing: servers normally do not sleep, and remote session drops are usually network timeouts.
If the "YouTube tab" method works for you, NoSleepR will work too but without wasting power or being ridiculous.
Bug reports, suggestions, and contributions are welcome:
License: CC-BY-4.0