| Title: | Import Multiple Files From a Single Directory at Once | 
| Version: | 1.1.3 | 
| Description: | The goal of tor (to-R) is to help you to import multiple files from a single directory at once, and to do so as quickly, flexibly, and simply as possible. | 
| License: | GPL-3 | 
| URL: | https://github.com/maurolepore/tor, https://maurolepore.github.io/tor/ | 
| BugReports: | https://github.com/maurolepore/tor/issues | 
| Depends: | R (≥ 3.2) | 
| Imports: | fs, readr, rlang, tibble | 
| Suggests: | covr, knitr, rmarkdown, spelling, testthat (≥ 3.0.0), withr | 
| Config/testthat/edition: | 3 | 
| Encoding: | UTF-8 | 
| Language: | en-US | 
| RoxygenNote: | 7.3.2 | 
| NeedsCompilation: | no | 
| Packaged: | 2024-07-14 23:13:54 UTC; rstudio | 
| Author: | Mauro Lepore | 
| Maintainer: | Mauro Lepore <maurolepore@gmail.com> | 
| Repository: | CRAN | 
| Date/Publication: | 2024-07-14 23:40:02 UTC | 
tor: Import Multiple Files From a Single Directory at Once
Description
The goal of tor (to-R) is to help you to import multiple files from a single directory at once, and to do so as quickly, flexibly, and simply as possible.
Author(s)
Maintainer: Mauro Lepore maurolepore@gmail.com (ORCID)
See Also
Useful links:
- Report bugs at https://github.com/maurolepore/tor/issues 
Import multiple files of any format from a directory into a list.
Description
Import multiple files of any format from a directory into a list.
Usage
list_any(
  path = ".",
  .f,
  regexp = NULL,
  ignore.case = FALSE,
  invert = FALSE,
  ...
)
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.  | 
| ignore.case | if  | 
| invert | If  | 
| ... | Additional arguments passed to  | 
Value
A list.
See Also
Other functions to import files into a list: 
list_csv()
Other functions to import files of any format: 
load_any()
Examples
tor_example()
(path <- tor_example("csv"))
dir(path)
list_any(path, read.csv)
list_any(path, ~ read.csv(.x, stringsAsFactors = FALSE))
(path_mixed <- tor_example("mixed"))
dir(path_mixed)
list_any(
  path_mixed, ~ get(load(.x)),
  "[.]Rdata$",
  ignore.case = TRUE
)
list_any(
  path_mixed, ~ get(load(.x)),
  regexp = "[.]csv$",
  invert = TRUE
)
Import multiple common files from a directory into a list.
Description
These functions wrap common use-cases of list_any().
Usage
list_csv(
  path = ".",
  regexp = "[.]csv$",
  ignore.case = TRUE,
  invert = FALSE,
  ...
)
list_tsv(
  path = ".",
  regexp = "[.]tsv$",
  ignore.case = TRUE,
  invert = FALSE,
  ...
)
list_rds(path = ".", regexp = "[.]rds$", ignore.case = TRUE, invert = FALSE)
list_rdata(
  path = ".",
  regexp = "[.]rdata$|[.]rda$",
  ignore.case = TRUE,
  invert = FALSE
)
Arguments
| path | A character vector of one path. Defaults to the working directory. | 
| regexp | A regular expression (e.g.  | 
| ignore.case | if  | 
| invert | If  | 
| ... | Arguments passed to  | 
Value
A list.
See Also
Other functions to import files into a list: 
list_any()
Other functions to import files of common formats: 
load_csv()
Examples
(rds <- tor_example("rds"))
dir(rds)
list_rds(rds)
(tsv <- tor_example("tsv"))
dir(tsv)
list_tsv(tsv)
(mixed <- tor_example("mixed"))
dir(mixed)
list_rdata(mixed)
list_csv(mixed)
list_rdata(mixed, regexp = "[.]RData", ignore.case = FALSE)
Import multiple files of any format from a directory into an environment.
Description
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.  | 
| ignore.case | if  | 
| invert | If  | 
| envir | an  | 
| ... | Additional arguments passed to  | 
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)
# The data is now available in the environment `e`
e$rdata1
e$rdata2
Import multiple common files from a directory into an environment.
Description
These functions wrap common use-cases of load_any().
Usage
load_csv(
  path = ".",
  regexp = "[.]csv$",
  ignore.case = TRUE,
  invert = FALSE,
  envir = .GlobalEnv,
  ...
)
load_tsv(
  path = ".",
  regexp = "[.]tsv$",
  ignore.case = TRUE,
  invert = FALSE,
  envir = .GlobalEnv,
  ...
)
load_rds(
  path = ".",
  regexp = "[.]rds$",
  ignore.case = TRUE,
  invert = FALSE,
  envir = .GlobalEnv
)
load_rdata(
  path = ".",
  regexp = "[.]rdata$|[.]rda$",
  ignore.case = TRUE,
  invert = FALSE,
  envir = .GlobalEnv
)
Arguments
| path | A character vector of one path. Defaults to the working directory. | 
| regexp | A regular expression (e.g.  | 
| ignore.case | if  | 
| invert | If  | 
| envir | an  | 
| ... | Arguments passed to  | 
Value
invisible(path).
See Also
Other functions to import files into an environment: 
load_any()
Other functions to import files of common formats: 
list_csv()
Examples
(path_csv <- tor_example("csv"))
dir(path_csv)
load_csv(path_csv)
# Each file is now available in the global environment
csv1
csv2
(path_mixed <- tor_example("mixed"))
dir(path_mixed)
# Loading the data in an environment other than the global environment
e <- new.env()
load_rdata(path_mixed, envir = e)
# Each dataframe is now available in the environment `e`
e$lower_rdata
e$upper_rdata
Easily access example data.
Description
Easily access example data.
Usage
tor_example(path = NULL)
Arguments
| path | Length-1 character vector. A path to an available directory. | 
Value
A character string listing available directories or a length-1 string giving a path to a directory.
Author(s)
Copied from readr_example() from the readr package, by Jim
Hester and colleagues.
Examples
tor_example()
tor_example("csv")
dir(tor_example("csv"))