Learn R Programming

NoSleepR (version 0.2.0)

nosleep_on: Turn nosleep on

Description

Prevent the operating system from suspending or putting the display to sleep while long-running R work is executing.

Usage

nosleep_on(keep_display = FALSE)

Value

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.

Arguments

keep_display

logical. If TRUE, also prevent the display from powering off (when supported by the underlying OS). Default is FALSE.

Details

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.

Examples

Run this code

# Simple usage
if (FALSE) {
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)
}

Run the code above in your browser using DataLab