Import multiple files of any format from a directory into an environment.

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 to grep() to filter paths.

ignore.case

if FALSE, the pattern matching is case sensitive and if TRUE, case is ignored during matching.

invert

If TRUE return files which do not match

envir

an environment or NULL.

...

Additional arguments passed to .f.

Value

invisible(path).

See also

Other functions to import files into an environment: load_csv()

Other functions to import files of any format: list_any()

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