Read a lot of datasets at once with R
I often have to read a lot of datasets at once using R. So I’ve wrote the following function to solve this issue:
read_list <- function(list_of_datasets, read_func){ read_and_assign <- function(dataset, read_func){ dataset_name <- as.name(dataset) dataset_name <- read_func(dataset) } # invisible is used to suppress the unneeded output output <- invisible( sapply(list_of_datasets, read_and_assign, read_func = read_func, simplify = FALSE, USE.NAMES = TRUE)) # Remove the extension at the end of the data set names names_of_datasets <- c(unlist(strsplit(list_of_datasets, "[.]"))[c(T, F)]) names(output) <- names_of_datasets return(output) }You need to supply a list of datasets as well as the function to read the datasets to read_list. So for example to read ... [Read more...]