bulk_read_csv {fritools2}R Documentation

Bulk Read Comma Separated Files

Description

Import a bunch of comma separated files or all comma separated files below a directory using read_csv.

Usage

bulk_read_csv(
  paths,
  stop_on_error = FALSE,
  is_latin1 = TRUE,
  pattern = ".*\\.csv$",
  all_files = TRUE,
  recursive = FALSE,
  ignore_case = FALSE,
  find_all = FALSE,
  select = NA,
  ...
)

Arguments

paths

A vector of file paths or the directory to find files.

stop_on_error

Stop if any of the files is not read? Warn and continue otherwise.

is_latin1

Are the files encoded in "Latin1"?

pattern

see find_files. Ignored, if paths is not a directory.

all_files

see find_files. Ignored, if paths is not a directory.

recursive

see find_files. Ignored, if paths is not a directory.

ignore_case

see find_files. Ignored, if paths is not a directory.

find_all

see find_files. Ignored, if paths is not a directory.

select

see find_files. Ignored, if paths is not a directory.

...

Arguments passed to read_csv.

Value

A named list, each element holding the contents of one csv file read by read_csv.

See Also

Other CSV functions: bulk_write_csv(), check_ascii_file(), csv2csv(), csv

Examples

unlink(dir(tempdir(), full.names = TRUE))
data(mtcars)
mt_german <- mtcars
rownames(mt_german)[1] <- "Mazda R\u00f64"
names(mt_german)[1] <- "mg\u00dc"
#% read from directory
for (i in 1:10) {
    f <- file.path(tempdir(), paste0("f", i, ".csv"))
    write.csv(mtcars[1:5, TRUE], file = f)
    f <- file.path(tempdir(), paste0("f", i, "_german.csv"))
    write.csv2(mt_german[1:7, TRUE], file = f, fileEncoding = "Latin1")
}
bulk <- bulk_read_csv(tempdir())

#% pass a path
f <- list.files(tempdir(), pattern = ".*\\.csv$", full.names = TRUE)[1]
bulk <- bulk_read_csv(f)

#% pass multiple path
f <- list.files(tempdir(), pattern = ".*\\.csv$", full.names = TRUE)[2:4]
bulk <- bulk_read_csv(f)

[Package fritools2 version 4.1.0 Index]