File: make_holidays.R

package info (click to toggle)
r-cran-prophet 1.0%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 740 kB
  • sloc: makefile: 15; sh: 13
file content (46 lines) | stat: -rw-r--r-- 1,536 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Copyright (c) Facebook, Inc. and its affiliates.

# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.


#' Return all possible holiday names of given country
#'
#' @param country.name Country name (character).
#'
#' @return A vector of all possible holiday names (unique) of given country.
#' @keywords internal
get_holiday_names <- function(country.name){
    holidays <- generated_holidays %>% 
      dplyr::filter(country == country.name) %>%
      dplyr::select(holiday) %>%
      unique()
  return(holidays$holiday)
}


#' Make dataframe of holidays for given years and countries
#'
#' @param years List of years for which to include holiday dates.
#' @param country.name Country name (character).
#'
#' @return Dataframe with 'ds' and 'holiday', which can directly feed
#'  to 'holidays' params in Prophet
#' @keywords internal
make_holidays_df <- function(years, country.name){
  country.holidays = generated_holidays %>%
    dplyr::filter(country == country.name)
  max.year <- max(country.holidays$year)
  min.year <- min(country.holidays$year)
  if (max(years) > max.year ||  min(years) < min.year){
    warning.msg = paste("Holidays for", country.name, "are only supported from", min.year, 
                        "to", max.year)
    warning(warning.msg)
  }
  holidays.df <- country.holidays %>%
    dplyr::filter(year %in% years) %>%
    dplyr::select(ds, holiday) %>%
    dplyr::mutate(ds = as.Date(ds)) %>%
    data.frame
  return(holidays.df)
}