Learn R Programming

TimeWarp (version 1.0.15)

holidays: TimeWarp Holiday Database

Description

Functions for querying and manipulating the TimeWarp holiday database

Usage

holidays(years, type, silent = FALSE)
addToHolidays(type,dates)
registerHolidays(type,dates)
unregisterHolidays(type,dates)
allHolidays()
isHoliday(dates, type)

Arguments

years

numeric vector of years for which to return holiday dates.

type

character string, name of the holiday.

dates

a Date vector, or a character vector that can be converted to Date by dateParse.

silent

do not display warnings.

Value

holidays returns a Date vector of holidays that fall within the years argument for the given holiday type.

addToHolidays and registerHolidays invisibly return a copy of the data.frame for the given type.

unregisterHolidays invisibly returns NULL.

allHolidays returns a character vector of all holiday type's known to the database.

isHoliday returns a logical vector with TRUE of all holidays in input.

Details

The TimeWarp holidays database is implemented as an internal named, or type'd, list of data.frame's.

To create a new type of holiday, use registerHolidays. unregisterHolidays will delete the holiday named by type, and addToHolidays will add new days to an existing type of holiday.

allHolidays returns a character vector of all the known holiday types.

Examples

Run this code
# NOT RUN {
# Create a holiday type of New Year days for the 20th century.
registerHolidays('NEWYEAR', as.Date(ISOdate(1900:2000,1,1)))

# Return all New Year days for the 1990's
holidays(1990:2000,'NEWYEAR')

# View counts of registered holidays by year
sapply(as.character(1998:2012), function(y)
       sapply(allHolidays(), function(h) length(holidays(y, h, silent=TRUE))))

# }

Run the code above in your browser using DataLab