R/hfr_filterpd.R

Defines functions hfr_filter_pd

Documented in hfr_filter_pd

#' Filter to Select HFR Period
#'
#' Limits data frame to only the current reporting period when the fiscal year
#' and period are provided.
#'
#' @param df HFR data frame imported via `hfr_import()`
#' @param hfr_pd_sel HFR reporting period, 1-13, no filter when NULL, default = NULL
#' @param hfr_fy_sel fiscal year, default = NULL
#'
#' @export

hfr_filter_pd <- function(df, hfr_pd_sel = NULL, hfr_fy_sel = NULL){

  if(is.null(hfr_fy_sel))
   hfr_fy_sel <- curr_fy

  if(!is.numeric(hfr_fy_sel))
    stop("Enter hfr_fy_sel as an integer, eg 2021")

  if(!is.null(hfr_pd_sel) && !is.numeric(hfr_pd_sel))
    stop("Enter hfr_pd_sel as an integer between 1 and 13")

  if(!is.null(hfr_pd_sel))
    df <- df %>%
      dplyr::filter(fy == hfr_fy_sel,
                    hfr_pd == hfr_pd_sel)
  return(df)
}
USAID-OHA-SI/Wavelength documentation built on March 24, 2023, 10:07 a.m.