R/read_metadata.R

#' TITLE read_metadata
#'
#' DESCRIPTION
#'
#' @param path DESCRIPTION.
#' @param years DESCRIPTION.
#' @param ids DESCRIPTION.
#'
#' @return list DESCRIPTION
#' @examples read_metadata(years = c(2019),
#'                         ids = list(c(4:18)))
#'
#' @import dplyr
#' @import readODS
#'
#' @export

read_metadata = function(path = "./data/masterdata.ods",
                         years,
                         ids) {

  # years = c(2019)
  # ids = list(c(4:18))

  stopifnot(length(years) == length(ids))

  md_sheets = readODS::ods_sheets(path = path)
  md_list = lapply(X = file_sheets,
                   FUN = function(x) suppressMessages(
                     readODS::read_ods(path = path,
                                       sheet = x,
                                       col_names = TRUE)))

  names(md_list) = md_sheets

  md_list$LIST = dplyr::rbind_list(
    lapply(X = seq_along(years),
           FUN = function(x) md_list$LIST %>%
             dplyr::filter(YEAR == years[x] & NR %in% ids[[x]])))

  return(md_list)

}
hewag1975/ACprogram documentation built on May 13, 2019, 10:27 a.m.