Package 'naptime'

Title: A Flexible and Robust Sys.sleep() Replacement
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.
Authors: Russell S. Pierce [aut, cre], Timothy Gann [aut]
Maintainer: Russell S. Pierce <[email protected]>
License: GPL-2
Version: 1.3.0
Built: 2024-11-04 04:49:52 UTC
Source: https://github.com/russellpierce/naptime

Help Index


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 naptime.permissive option for this call of the naptime function

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)