NoSleepR

Continuous Integration GitHub issues License CodeQL

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.

Installation

Install the development version directly from GitHub:

# install.packages("devtools")
devtools::install_github("hetalang/NoSleepR")
library(NoSleepR)

Usage

Basic usage

nosleep_on()
# long-running R code here
nosleep_off()

Block-style usage

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
})

Options

keep_display

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
})

Known limitations and recommendations

Some sleep behaviors are enforced by the operating system and cannot be overridden by NoSleepR or any similar tools.

  1. Closing the laptop lid or pressing the power button will force the system into sleep regardless of active sleep-prevent requests of NoSleepR.

  2. 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.

Remote sessions (SSH, Posit/RStudio Server)

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.

Author

License

MIT (see LICENSE.md).