get_holiday: Get the non-workdays or workdays

View source: R/get_holiday.R

get_holidayR Documentation

Get the non-workdays or workdays

Description

Get the non-workdays or workdays within one year. The function is intended for use when planning sampling to excluded days or weeks from the sampling plan.

Usage

get_holiday(
  year,
  type = "workday",
  exclude_trapped_days = FALSE,
  output = "selected"
)

Arguments

year

[integer(1)]
Year.

type

[character(1)]
The type of non_workday or workday, see details. Defaults to "workday".

exclude_trapped_days

[character | logical(1)]
Should trapped days and common days off be excluded from workday?, see details. Defaults to FALSE.

output

[character(1)]
The output format of the data frame, see details. Defaults to "selected".

Details

type is used to select the type of non-workday or workday. Valid input are one of c("non_workday", "sat_to_sun", "public_holiday", "workday"). public_holiday are the non-moveable holidays, Easter and Pentacost; sat_to_sun are Saturdays and Sundays; and non_workday are public_holiday and sat_to_sun combined. workday is the opposite of non_workday when exclude_trapped_days = FALSE.

exclude_trapped_days is used to exclude trapped days and other days that many often takes a day off, i.e. the Easter week and the Christmas week. It is only Valid for workday and has no effect on the other types. Input "trapped" or TRUE will exclude trapped days, "easter" will exclude Monday to Wednesday before Thursday and "xmas" will exclude the days in the week of Christmas eve until New years eve.

The output is a data frame with the selected dates and the day_of_week (integer) when output = "selected". When output = "raw" the data frame includes all dates and the additional columns c("non_workday", "sat_to_sun", "public_holiday", "workday", "trapped" and "public"), see below for description.

The output data frame for output = "raw":

Column name Format Description
date date Date.
day_of_week integer Week day number, Monday = 1, Sunday = 7.
sat_to_sun integer Saturday and Sunday = 1, otherwise 0.
public_holiday integer Public holidays = 1 otherwise = 0.
non_workday integer Saturday, Sunday and public holidays = 1, otherwise = 0.
workday integer Workday, the opposite of non-workday when exclude_trapped_days = FALSE.
public character Easter = "e", Pentacost = "p", non-moveable = "n", otherwise NA.
trapped character trapped days (t), Easter week days (e) and/or Xmas week days (x) otherwise NA.

When output %in% c("fhi", "cstime") the data frame is formatted as the table cstime::nor_workdays_by_date created by National Public Health Institute (FHI).

The function is limited to years from 1968, as before 1968 Saturday was a normal workday in Norway. Be aware that Saturday was a normal school day in Norway until and including 1972.

Value

data frame with the selected dates.

Author(s)

Petter Hopp Petter.Hopp@vetinst.no

Examples

# Selects the public holidays
 public_holidays <- get_holiday(year = 2024,
                                type = "public_holiday")

# Selects workdays except the trapped days
 workdays <- get_holiday(year = 2024,
                         type = "workday",
                         exclude_trapped_days = TRUE)

# Selects workdays except days in Easter and Christmas week
 workdays <- get_holiday(year = 2024,
                         type = "workday",
                         exclude_trapped_days = c("easter", "xmas"))


NorwegianVeterinaryInstitute/OKplan documentation built on Dec. 20, 2024, 10:41 a.m.