Type: | Package |
Title: | A Flexible and Robust Sys.sleep() Replacement |
Version: | 1.3.1 |
Date: | 2025-04-07 |
Description: | Provides a near drop-in replacement for base::Sys.sleep() that allows more types of input to produce delays in the execution of code and can silence/prevent typical sources of error. |
License: | GPL-2 |
Imports: | methods, lubridate |
Suggests: | testthat, covr |
URL: | https://github.com/russellpierce/naptime |
BugReports: | https://github.com/russellpierce/naptime/issues |
RoxygenNote: | 7.3.2 |
Encoding: | UTF-8 |
NeedsCompilation: | no |
Packaged: | 2025-04-07 20:52:52 UTC; russell |
Author: | Russell S. Pierce [aut, cre], Timothy Gann [aut] |
Maintainer: | Russell S. Pierce <russell.s.pierce@gmail.com> |
Repository: | CRAN |
Date/Publication: | 2025-04-07 21:10:02 UTC |
Safe sleep function
Description
Acceptable inputs:
numeric: time in seconds to nap
POSIXct: time at which the nap should stop (timezone is respected)
character: Date or date time at which nap should stop formatted as yyyy-mm-dd hh:mm:ss, time zone is assumed to be Sys.timezone() and hh:mm:ss is optional as three formats may be missing, cf. lubridate::ymd_hms().
Period: time from now at which the nap should stop
difftime: difference in time to nap
logical: If TRUE, nap for default duration, otherwise don't nap.
NULL: don't nap
generic: error or nap for default duration depending on the option naptime.permissive
Usage
naptime(time, permissive = getOption("naptime.permissive", permissive_default))
## S4 method for signature 'numeric'
naptime(time, permissive = getOption("naptime.permissive", permissive_default))
## S4 method for signature 'Period'
naptime(time, permissive = getOption("naptime.permissive", permissive_default))
## S4 method for signature 'POSIXct'
naptime(time, permissive = getOption("naptime.permissive", permissive_default))
## S4 method for signature 'difftime'
naptime(time, permissive = getOption("naptime.permissive", permissive_default))
## S4 method for signature 'logical'
naptime(time, permissive = getOption("naptime.permissive", permissive_default))
## S4 method for signature 'NULL'
naptime(time, permissive = getOption("naptime.permissive", permissive_default))
## S4 method for signature 'character'
naptime(time, permissive = getOption("naptime.permissive", permissive_default))
Arguments
time |
Time to sleep, polymorphic type inputs, leaning towards units as 'seconds' |
permissive |
An optional argument to override the |
Details
The default duration is set with a numeric for the option naptime.default_delay
in seconds (default: 0.1)
Whether a generic input is accepted is determined by the option naptime.permissive
(default: FALSE)
Value
NULL; A side effect of a pause in program execution
Examples
## Not run:
naptime(1)
naptime(difftime("2016-01-01 00:00:01", "2016-01-01 00:00:00"))
## End(Not run)