View source: R/source-and-load.R
load_files | R Documentation |
Loads or reads in all files of the respective folder according to the parameters input.
load_files(
folder,
file.type.subset = character(),
file.type.ignore = character(),
file.subset = character(),
file.ignore = character(),
read.funs = list(),
recursive = FALSE,
verbose = TRUE
)
folder |
The absolute or relative directory to the folder of interest. |
file.type.subset |
The file types you want to load in specified as a character vector. Elements must start with '.' ('.csv', NOT: 'csv')! |
file.type.ignore |
The file types you don't want to load in specified as a character vector. Elements must start with '.' ('.csv', NOT: 'csv')! |
file.subset |
A regular expression that match the file names you want to load in specified as a character vector. |
file.ignore |
A regular expression that match the file names you want to be ignored specified as a character vector. |
read.funs |
A named list providing the functions that are supposed to be
used to load the respective file type. Names need to match the respective elements
of argument |
This function accesses the folder to which the directory leads. Via base::list.files()
it extracts
the directories to all files this folder contains and - if recursive
is set to TRUE - as well to all files all subsequent
folders contain.
The resulting vector of file directories will be processed according to the .subset
and/or the .ignore
arguments.
.subset
: Only the file directories that match one or more of the provided regular expressions will be read in.
.ignore
: All file directories that match one or more of the provided regular expressions will be discarded and not read in.
After the filtering step every remaining file directory will be given to a specific function in order to be read in. These functions
have to be provided in a named list as input of the read.funs
-argument. Default functions are:
utils::read.csv for files of type .csv
readxl::read.xls for files of type .xls
readxl::read.xls for files of type .xlsx
base::readRDS for files of type .rds
base::load for files of type .RData - can not be overwritten
Remaining file directories ending with abbreviations that are not specified within the default functions or within read.funs
will be discarded and not read in. In order to add new functions for new file types or overwrite default functions specify those in
a named list in read.funs
(e.g. list(".tif" = magick::image_read)).
Via base::assign()
every read in object will be stored in the global environment whereby it's object name is the file name without
the file type specifiying abbreviation.
Loaded files in the global environment as a side effect and returns an invisible logical value: TRUE.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.