calculate_flu_start: Calculate the date flu season begins each year

calculate_flu_startR Documentation

Calculate the date flu season begins each year

Description

Assuming flu season starting on Sunday of week 35 each year, providing the year will return the full date this begins.

Usage

calculate_flu_start(
  year = format(Sys.Date(), "%Y"),
  week = NA,
  flu_wk_start = 35L,
  week_start = 7
)

Arguments

year

Character vector of years to determine flu week start dates (default is current year).

week

Optional parameter for higher resolution of flu week start based on flu_wk_start parameter.

flu_wk_start

Week of the year that flu season begins (default set to 35).

week_start

Integer value for start of week (default: 7, Sunday).

Details

For a higher resolution, you can provide a week number to the week parameter. For example, on week 1 of Jan 2023, it may be desired to have the 2022 flu year as reference instead of 2023. This avoids some manipulation of inputs using other functions like convert_date2fluseason. However, unlike the year parameter, this is not currently vectorized and requires mapply to assist in looping, see examples.

Value

Vector of dates.

Examples

## Not run: 
# Find start dates for each week...
calculate_flu_start(2022); calculate_flu_start('2022');
calculate_flu_start('2022') + seq(0, 7*10, by =7)
calculate_flu_start(c(2020, 2021, 2022))
lapply(calculate_flu_start(c(2020, 2021, 2022)), function(x) x + seq(0, 7*10, by =7))

# Using weekly resolution
calculate_flu_start(2022, 34)
mapply(calculate_flu_start, c(2022, 2022), week = c(34,35), SIMPLIFY = FALSE) # As list
do.call('c', mapply(calculate_flu_start, c(2022, 2022), week = c(34,35), SIMPLIFY = FALSE)) # As vector
Reduce('c', mapply(calculate_flu_start, c(2022, 2022), week = c(34,35), SIMPLIFY = FALSE)) # Same as above in effect

## End(Not run)

al-obrien/farrago documentation built on April 14, 2023, 6:20 p.m.