| Title: | Prevent System Sleep During Long R Tasks |
|---|---|
| Description: | Provides a cross-platform interface to prevent the operating system from going to sleep while long-running R tasks are executing. |
| Authors: | Evgeny Metelkin [aut, cre] |
| Maintainer: | Evgeny Metelkin <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.2.0 |
| Built: | 2026-06-03 14:59:42 UTC |
| Source: | https://github.com/hetalang/nosleepr |
Turn off a specific nosleep request or, if no handle is supplied, every active request opened by the current R session.
nosleep_off(handle)nosleep_off(handle)
handle |
Optional |
Invisibly returns NULL.
## Not run: h <- nosleep_on() # ... do work ... nosleep_off(h) # Equivalent shortcut to clear everything nosleep_on() nosleep_on() nosleep_off() ## End(Not run)## Not run: h <- nosleep_on() # ... do work ... nosleep_off(h) # Equivalent shortcut to clear everything nosleep_on() nosleep_on() nosleep_off() ## End(Not run)
Prevent the operating system from suspending or putting the display to sleep while long-running R work is executing.
nosleep_on(keep_display = FALSE)nosleep_on(keep_display = FALSE)
keep_display |
logical. If |
The returned handle must stay alive for as long as you want the nosleep
request to remain in effect. Call nosleep_off() with the handle to
release the underlying system resource as soon as the protected work is
complete.
If no backend is available for the current platform (e.g., missing
dependencies), a warning is issued and invisible NULL is returned.
An object of class "NoSleepR_handle" that stores the active
nosleep request for the current platform. Invisible NULL is
returned when the request could not be established.
# Simple usage ## Not run: nosleep_on() long_running_job() nosleep_off() # Handle-based usage h <- nosleep_on() long_running_job() nosleep_off(h) # Keep the display awake as well (when supported) h <- nosleep_on(keep_display = TRUE) Sys.sleep(100) # simulate long job nosleep_off(h) ## End(Not run)# Simple usage ## Not run: nosleep_on() long_running_job() nosleep_off() # Handle-based usage h <- nosleep_on() long_running_job() nosleep_off(h) # Keep the display awake as well (when supported) h <- nosleep_on(keep_display = TRUE) Sys.sleep(100) # simulate long job nosleep_off(h) ## End(Not run)
NoSleepR exposes a tiny, cross-platform API that temporarily disables system
sleep while your R script performs a long-running operation. The package
delegates to the native inhibition mechanisms shipped with each platform
(Win32 power requests, caffeinate, or systemd-inhibit) and automatically
tears them down once you are done.
Core helpers
nosleep_on() — establish a sleep-prevention request and keep the
handle alive for as long as the work runs.
nosleep_off() — release a specific handle or clear all active
ones when called without arguments.
with_nosleep() — wrap a code block so that NoSleepR turns itself
on before the block executes and reliably shuts down after it completes
or errors.
All helpers accept the optional keep_display flag, allowing you to request
that the monitor stays on (when supported by the OS) in addition to the
system-wide sleep prevention.
Call nosleep_on() (optionally with keep_display = TRUE) right
before a long computation or data transfer.
Run the expensive task.
Explicitly stop the request with nosleep_off() as soon as the work
finishes, or rely on with_nosleep() to bracket the code block.
NoSleepR automatically cleans up pending requests when the R session ends,
but it is still best practice to explicitly call nosleep_off() so that the
operating system can resume managing power immediately after the protected
job completes.
Maintainer: Evgeny Metelkin [email protected]
https://github.com/hetalang/NoSleepR
Helper that automatically brackets an expression with nosleep_on()
and nosleep_off().
with_nosleep(expr, keep_display = FALSE)with_nosleep(expr, keep_display = FALSE)
expr |
Expression to execute while nosleep is on. |
keep_display |
logical. If TRUE, also prevent the display from sleeping. |
The result of evaluating expr.
## Not run: with_nosleep({ message("Downloading a large file…") download_large_file() }) ## End(Not run)## Not run: with_nosleep({ message("Downloading a large file…") download_large_file() }) ## End(Not run)