R/previous_year.R

Defines functions previous_year

Documented in previous_year

previous_year <-
function(x = Sys.Date(),
         n = 1, 
         part = getOption("timeperiodsR.parts")){
  
  if ( ! inherits(x, "Date") ) {
    x <- as.Date(x)
  }
  
  start <- floor_date( x, unit = "year" ) - years(n)
  stop  <- start + years(1) - days(1)
  out   <- custom_period(start, stop)
  
  part <- match.arg(part, getOption("timeperiodsR.parts"))
  
  if ( part == "all" ) {
    return(out) 
  } else {
    return(out[[part]]) 
  } 
}
selesnow/timeperiodsR documentation built on Jan. 27, 2024, 7:32 a.m.