Skip to contents

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. [.]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.

...

Arguments passed to readr::read_csv() or readr::read_tsv().

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"))
#> [1] "/home/runner/work/_temp/Library/tor/extdata/csv"
dir(path_csv)
#> [1] "csv1.csv" "csv2.csv"

load_csv(path_csv)
#> Rows: 2 Columns: 1
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: ","
#> dbl (1): x
#> 
#>  Use `spec()` to retrieve the full column specification for this data.
#>  Specify the column types or set `show_col_types = FALSE` to quiet this message.
#> Rows: 2 Columns: 1
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: ","
#> chr (1): y
#> 
#>  Use `spec()` to retrieve the full column specification for this data.
#>  Specify the column types or set `show_col_types = FALSE` to quiet this message.
# Each file is now available in the global environment
csv1
#> # A tibble: 2 × 1
#>       x
#>   <dbl>
#> 1     1
#> 2     2
csv2
#> # A tibble: 2 × 1
#>   y    
#>   <chr>
#> 1 a    
#> 2 b    

(path_mixed <- tor_example("mixed"))
#> [1] "/home/runner/work/_temp/Library/tor/extdata/mixed"
dir(path_mixed)
#> [1] "csv.csv"           "lower_rdata.rdata" "rda.rda"          
#> [4] "upper_rdata.RData"

# 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
#> # A tibble: 2 × 1
#>   y    
#>   <chr>
#> 1 a    
#> 2 b    
e$upper_rdata
#> # A tibble: 2 × 1
#>   y    
#>   <chr>
#> 1 a    
#> 2 b