Batch Import and Process Kaleidoscope Files in Parallel
Source:R/import_kaleidoscope_batch.R
import_kaleidoscope_batch.Rd
This function imports and processes multiple Excel files (.xlsx or .xls) from the specified directory or file list using the import_kaleidoscope
function. The function operates in parallel to speed up the process by utilizing multiple cores. The processed data from each file is row-bound into a single data frame, and a new column (specified by the user) is added with a constant value.
Usage
import_kaleidoscope_batch(
file_list = NULL,
new.col.name,
new.col.value,
path = getwd(),
cores = NULL
)
Arguments
- file_list
A list of Excel files to be imported. If NULL, the function will search for Excel files in the specified
path
(default is the working directory).- new.col.name
The name of the new column to be added to the output data frame.
- new.col.value
The value that will be assigned to the new column for all rows.
- path
The path to the directory containing the Excel files. Default is the working directory.
- cores
The number of CPU cores to use for parallel processing. If NULL, the function will use all but one available core.
Value
A data frame combining the imported and processed data from all Excel files, with the new column added.
Examples
# Assuming there are Excel files in the working directory:
result <- import_kaleidoscope_batch(new.col.name = "treatment", new.col.value = "test")
#> Loading required package: foreach
#> Loading required package: iterators
#> Error in import_kaleidoscope_batch(new.col.name = "treatment", new.col.value = "test"): No Excel files found in the specified directory.
# Specifying a list of files and a custom path:
file_list <- c("file1.xlsx", "file2.xlsx")
result <- import_kaleidoscope_batch(file_list = file_list, new.col.name = "batch", new.col.value = "batch_1", path = "path/to/files")
#> Error in { df <- import_kaleidoscope(file) df[[new.col.name]] <- new.col.value return(df)}: task 1 failed - "`path` does not exist: 'file1.xlsx'"