123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- #!/usr/bin/env Rscript
- # Load the openxlsx package
- library(openxlsx)
- args <- commandArgs(TRUE)
- outDir <- args[1]
- # Function to combine CSV and TXT files into a workbook with named sheets
- combineFilesToWorkbook <- function(file_list, output_file) {
- # Create a new workbook
- wb <- createWorkbook()
-
- # Loop through the file list
- for (i in seq_along(file_list)) {
- file <- file_list[i]
-
- # Extract the sheet name from the file name based on the extension
- ext <- tools::file_ext(file)
- sheet_name <- tools::file_path_sans_ext(basename(file))
-
- # Read the data based on the file extension
- if (ext %in% c("csv", "txt")) {
- if (ext == "csv") {
- data <- read.csv(file)
- } else if (ext == "txt") {
- data <- readLines(file)
- }
-
- # Create a new sheet in the workbook with the extracted sheet name
- addWorksheet(wb, sheetName = sheet_name)
-
- # Write the data to the sheet
- writeData(wb, sheet = sheet_name, x = data)
- }
- }
-
- # Save the workbook as an Excel file
- saveWorkbook(wb, output_file)
- }
- Component <- file.path(outDir, "Component", "ComponentResults.txt")
- Function <- file.path(outDir, "Function", "FunctionResults.txt")
- Process <- file.path(outDir, "Process", "ProcessResults.txt")
- # Specify the list of input files (both CSV and TXT)
- file_list <- c(Component, Process, Function)
- # Specify the output file name
- output_file <- file.path(outDir, "GTFCombined.xlsx")
- # Call the function to combine the files into a workbook with named sheets
- combineFilesToWorkbook(file_list, output_file)
|