R/hfr_restrict_cols.R

Defines functions hfr_restrict_cols

Documented in hfr_restrict_cols

#' Restrict HFR data frame columns
#'
#' Limits the  datafram to only have the exact columsn found in the template,
#' removing any extras
#'
#' @param df HFR data frame imported via `hfr_import()`
#'
#' @export

hfr_restrict_cols <- function(df){

  if(var_exists(df, "val")){
    cols <- intersect(template_cols_long, names(df))
  } else if(var_exists(df, "hts_tst.NA.NA")){
    cols <- intersect(template_cols_wide_lim, names(df))
  } else {
    cols <- intersect(template_cols_wide, names(df))
  }
    df <- dplyr::select_at(df, cols)

  return(df)
}
USAID-OHA-SI/Wavelength documentation built on March 24, 2023, 10:07 a.m.