##
## Attaching package: 'lubridate'
## The following object is masked from 'package:base':
##
## date
The premise of naptime is two fold.
In response to these considerations naptime::naptime()
either sleeps for the specified duration, or passes forward with a warning. It has the same argument name as base::Sys.sleep()
and a nearly identical behavior in response to numeric inputs. As such, it can be nearly used as a drop-in replacement for base::Sys.sleep()
.
The one notable exception to identical behavior is the input value of Inf
. base::Sys.sleep()
will sleep indefiniately in reponse to Inf
. In contrast, naptime::naptime()
will sleep the default duration.
All options are set via base::options()
.
naptime.default_delay
. If left unchanged, the default delay is .1
seconds.naptime.warnings
. If left unchanged, the default is TRUE
, to show warnings.naptime() accepts a wide variety of inputs.
naptime(1)
naptime(NULL)
#> Warning in nap_warn("NULL passed to naptime(), sleeping for .Options
#> $naptime.default_delay seconds."): NULL passed to naptime(), sleeping
#> for .Options$naptime.default_delay seconds.
#> [1] 0.1
naptime(lubridate::now(tzone = "UTC")+lubridate::seconds(1))
naptime(lubridate::seconds(1))
r naptime(as.character(lubridate::now() + lubridate::seconds(1)))
* difftime: difference in time to nap
r naptime(difftime(lubridate::now() + seconds(1), lubridate::now()))
* logical: nap for default duration
naptime(TRUE)
#> Warning in nap_warn("Logical passed to naptime(), sleeping for 0
#> seconds."): Logical passed to naptime(), sleeping for 0 seconds.
#> [1] 0.1
r naptime(glm(rnorm(5) ~ rnorm(5))) #> Warning in model.matrix.default(mt, mf, contrasts): the response appeared #> on the right-hand side and was dropped #> Warning in model.matrix.default(mt, mf, contrasts): problem with term 1 in #> model.matrix: no columns are assigned #> Warning in nap_warn("unhandled input for naptime: ", as.character(e), "; sleeping for default duration"): unhandled input for naptime: Error in (function (classes, fdef, mtable) : unable to find an inherited method for function 'naptime' for signature '"glm"' #> ; sleeping for default duration #> [1] 0.1
If you find a reasonable input-type for which naptime::naptime()
doesn’t have a reasonable response, please file an issue.
In addition, naptime will handle some specific errors: * All negative intervals will be converted to a delay of 0 * All non-finite intervals will be converted to a default delay * All inputs that produce an error will be converted to a default delay
library(devtools)
install_github("drknexus/naptime")
library(naptime)