R/next_n_weeks.R

Defines functions next_n_weeks

Documented in next_n_weeks

next_n_weeks <-
function(x = Sys.Date(),
           n = 1, 
           part = getOption("timeperiodsR.parts"),
           week_start = 1,
           include_current = F) {
    
    if ( ! inherits(x, "Date") ) {
      x <- as.Date(x)
    }
    
    start <- floor_date( x, unit = "week", week_start ) + weeks(ifelse( isTRUE(include_current), 0, 1)) 
    stop  <- ceiling_date( x, unit = "week", week_start ) + days(7 * n) 
    out   <- custom_period(start, stop)
    
    part <- match.arg(part, getOption("timeperiodsR.parts"))
    
    if ( part == "all" ) {
      return(out) 
    } else {
      return(out[[part]]) 
    } 
  }

Try the timeperiodsR package in your browser

Any scripts or data that you put into this service are public.

timeperiodsR documentation built on April 20, 2023, 5:13 p.m.