R/read_file.R

Defines functions combine_files_from_folder

Documented in combine_files_from_folder

#' Combine CSV and TXT Files from a Folder
#'
#' This function reads all CSV and TXT files from a specified folder and combines them
#' into a single data.table.
#'
#' @param folder_path The path to the folder containing the CSV or TSV files.
#' @return A data.table containing the combined data from all files.
#' @import data.table
#'
#' @examples
#' folder_path <- ""
#' combined_df <- combine_files_from_folder(folder_path)
#' print(combined_df)
#'
#' @export
combine_files_from_folder <- function(folder_path) {
  # List all CSV and TXT files in the folder
  file_list <- list.files(folder_path, pattern = "\\.csv$|\\.tsv$", full.names = TRUE)

  # Read and combine files using data.table's fread and rbindlist functions
  combined_df <- rbindlist(lapply(file_list, fread))

  return(combined_df)
}

Try the PepMapViz package in your browser

Any scripts or data that you put into this service are public.

PepMapViz documentation built on April 3, 2025, 6:29 p.m.