forked from topfm/poolER
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcombineAll.R
More file actions
28 lines (20 loc) · 851 Bytes
/
combineAll.R
File metadata and controls
28 lines (20 loc) · 851 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
library(tidyverse)
# Parse command line arguments
args <- commandArgs(trailingOnly = TRUE)
# Check if an input file was provided
if (length(args) == 0) {
stop("Please provide an input file name as a command-line argument.")
}
# Specify the directory containing CSV files
directory_path <- args[1]
# Get a list of all CSV files in the directory
csv_files <- list.files(directory_path, pattern = "\\.csv$", full.names = TRUE)
print(csv_files)
# Function to read and process each CSV file
read_and_process_csv <- function(file_path) {
read_csv(file_path, col_types = cols()) # Adjust col_types if needed
}
# Map, read, and combine all CSV files into a single dataframe
combined_data <- map_dfr(csv_files, read_and_process_csv, .id = "file_id")
# Write the combined dataframe to a new CSV file
write_csv(combined_data, "combined_data.csv")