R/my_csv_reader.R

Defines functions my_csv_reader

Documented in my_csv_reader

#' my_csv_reader
#'
#' Read multiple CSV files into a list
#' @param folderPath Path to folder which contains the CSV files to be read
#' @return List containing data from the CSV files
#' @import assertthat
#' @importFrom utils read.csv2
#' @examples
#' my_csv_reader("/User/Documents/CsvFolder")
#' @export

my_csv_reader <- function(folderPath) {
  assert_that(is.dir(folderPath))
  assert_that(is.readable(folderPath))
  fileNames <- list.files(path = folderPath, pattern = ".*csv$", full.names = TRUE)
  fileList <- list()
  for (fileName in fileNames) {
    fileList[[fileName]] <- (as.list(read.csv2(file = fileName)))
  }
  return(fileList)
}
megahf/megahhomework documentation built on May 29, 2019, 4:42 a.m.