Import multiple files of any format from a directory into an environment.
Source:R/load_any.R
load_any.Rd
Import multiple files of any format from a directory into an environment.
Usage
load_any(
path = ".",
.f,
regexp = NULL,
ignore.case = FALSE,
invert = FALSE,
envir = .GlobalEnv,
...
)
Arguments
- path
A character vector of one path. Defaults to the working directory.
- .f
A function able to read the desired file format.
- regexp
A regular expression (e.g.
[.]csv$
) passed on togrep()
to filter paths.- ignore.case
if
FALSE
, the pattern matching is case sensitive and ifTRUE
, case is ignored during matching.- invert
If
TRUE
return files which do not match- envir
an
environment
orNULL
.- ...
Additional arguments passed to
.f
.
Examples
e <- new.env()
load_any(tor_example("rdata"), .f = ~ get(load(.x)), envir = e)
ls(e)
#> [1] "rdata1" "rdata2"
# The data is now available in the environment `e`
e$rdata1
#> # A tibble: 2 × 1
#> x
#> <dbl>
#> 1 1
#> 2 2
e$rdata2
#> # A tibble: 2 × 1
#> y
#> <chr>
#> 1 a
#> 2 b