Description Usage Arguments Value Examples
Read multiple files from a directory (folder) using reading engine supply by a function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
fun |
A function to read files from a directory. First argument of the function must be file path.
Example : |
path |
Character: Path to desired directory which contain file, default is "." working directory. (passed to |
pattern |
Character: Specify regular expression to match file extension and file names. (passed to |
... |
Argument to pass to |
invert |
Logical: If |
ignore.case |
If FALSE, the regular expression matching is case sensitive and if |
perl |
Logical: Should Perl-compatible regexps be used? (passed to |
fixed |
Logical: If |
all.files |
If |
recursive |
If |
no.. |
logical. Should both "." and ".." be excluded also from non-recursive listings? (passed to |
snake_case |
If |
A list of object returned by fun
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 | # Not run
if(FALSE){
# Read .csv file form working directory (default) using `utils::read.csv`.
## file names are set to each elements of the output.
read.dir(utils::read.csv) # default `pattern` is "\.csv$"
# Read .xlsx file from a directory using `readxl::read_excel`.
## Must specify regular expression to match file extension.
read.dir(readxl::read_excel, path = "path/to/dir" ,pattern = "\\.xlsx$")
# Read .rds file ; To also read form sub-directory set `recursive = TRUE` .
read.dir(readRDS, pattern = "\\.rds$", path = "path/to/dir" ,recursive = TRUE)
# Read files using multiple engine from multiple path and multiple file extension.
params <- list(fun = c(read_csv, readxl::read_excel),
path = c("path/to/dir_1", "path/to/dir_2"),
pattern = c("\\.csv$", "\\.xlsx$"))
purrr::pmap(params, read.dir)
# or using base R
ls <- vector("list", 2)
for(i in seq_along(params[[1]])){
ls[[i]] <- read.dir(fun = params[[1]][[i]], path = params[[2]][[i]],
pattern = params[[3]][[i]])
}
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.