File Handler for RDS Formatted Files
Using a list, load RDS formatted files into standard data frame. Allows for grouping multiple files into one data frame for processing.
See code below
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 29 30 31 32 33 34 35 36 |
#sample file handler # ---------------------------------------------------------- #' class for handling the sample files #' @param file directory location #' @param file_extenstion pattern to identify what files to load #' fileHandlerSample <- setClass("fileHandlerSample", slots = list(directory = "character" ,file_extenstion = "character" )) loadRDSFiles <- function(userobject){} # ---------------------------------------------------------- #' method loadRDSFiles used to load RDS files from #' specified directory #' @return list vector with samples from each file setMethod("loadRDSFiles","fileHandlerSample",function(userobject) { listRDSFiles <- list.files(path = userobject@directory , pattern = userobject@file_extenstion , full.names = TRUE) #check to see found RDS files try(if(length(listRDSFiles) < 1) stop("No RDS files found")) files <- list() #loop through list of files and load each one for(current_file in listRDSFiles) { #load the file, convert to corpus on the fly message(c(".... Loading file: ", current_file)) store_current_file <- readRDS(current_file) files <- c(files, store_current_file) rm(store_current_file) } return(files) }) |
Leave a Reply