Prevent your computer from entering sleep mode while long-running R tasks are running — and automatically restore normal system behavior when they finish or fail.
PowerRequestcaffeinatesystemd-inhibitInstall the development version directly from GitHub:
# install.packages("devtools")
devtools::install_github("hetalang/NoSleepR")
library(NoSleepR)nosleep_on()
# long-running R code here
nosleep_off()You can wrap a code block using with_nosleep() to ensure
sleep-prevention is enabled only for the duration of the block:
with_nosleep({
# long-running R code here
})Prevents the display from turning off (default is
FALSE):
nosleep_on(keep_display = TRUE)Or in block mode:
with_nosleep(keep_display = TRUE, {
# long-running code
})Some sleep behaviors are enforced by the operating system and cannot be overridden by NoSleepR or any similar tools.
Closing the laptop lid or pressing the power
button will force the system into sleep regardless of active
sleep-prevent requests of NoSleepR.
On Windows devices with Modern Standby (S0ix) running on battery power (DC mode) the OS may ignore sleep prevention signals after a 5 minutes of inactivity if the screen is turned off.
keep_display=TRUE to keep the
screen awake.NoSleepR only affects the machine where R actually runs.
If your code runs on a remote server, the package has no effect on your
local computer — and it won’t prevent disconnects in remote IDEs.
Most “remote sleep” problems are actually connection timeouts, not
the server going to sleep. This is normal: NoSleepR is
designed for local laptops/desktops, not for managing network
sessions.
For reliable long runs on a remote server, use tools like
tmux, screen, or built-in session-recovery
mechanisms of your IDE. There’s usually no need to keep your local
machine awake.
lares — https://github.com/laresbernardo/lares
Provides a dont_sleep() helper with similar purpose, but
relies on simulating mouse activity and depends on external tools.
It does not use system-level sleep-inhibit mechanisms
NoSleep.jl — https://github.com/hetalang/NoSleep.jl
Julia implementation of the same concept, using native OS
sleep-inhibition backends (Windows/macOS/Linux).
For Julia developers
MIT (see LICENSE.md).