util_bind: Bind External Files

Description Usage Arguments Details Author(s) Examples

View source: R/util_bind.R

Description

Binds csv, Excel, RData, or Rds files in a given directory by row (rbind).

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
util_bind(
  dir = getwd(),
  recursive = FALSE,
  format = "csv",
  pattern = "^filename.*",
  fn_column = TRUE,
  fn_column_full_path = FALSE,
  save = FALSE,
  fn_output = NULL,
  save_dir = getwd(),
  par = TRUE,
  ncores = NULL,
  ...
)

Arguments

dir

Character string. Directory which contains target files.

recursive

Logical. Search files recursively under dir.

format

Character string. "csv" for comma separated files. "xls" or "xlsx" for Excel files. "Rda", "rda", "RDA", "RData", "Rdata", "rdata", "RDATA" for R Data Format. "Rds", "rds", "RDS" for serialized R object.

pattern

Character string. Regular expression. Pattern of file names. format is appended as an extension. For example, if pattern = "^filename.*", and format = "csv", the pattern used to load files will be "^filename.*\\.csv$".

fn_column

Logical. Save file name of source data file as a new column. The new column will have "fn" as its column name.

fn_column_full_path

Logical. Save the full path of source data file as a new column.

save

Logical. Save concatenated files in csv format.

fn_output

Character string. Filename to use when save = TRUE. Uses the basename of dir if not provided.

save_dir

Character string. Directory used for fn_output.

par

Logical. If TRUE, use multiple cores.

ncores

Integer. Number of cores to use if par = TRUE. If unspecified, defaults to detectCores() - 1.

...

Optional arguments to pass to readxl::read_excel() when format = "xls" or "xlsx", read.csv() when format = "csv", load() when format = any of the following "Rda", "rda", "RDA", "RData", "Rdata", "rdata", "RDATA", or readRDS() when format = any of the following "Rds", "rds", "RDS".

Details

The function requires that files have the same data structure. For R object files. only vectors, matrices or data frames are allowed. By default, stringsAsFactors = FALSE when format = "csv".

Author(s)

Ivan Jacob Agaloos Pesigan

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
## Not run: 
util_bind(
  dir = getwd(),
  format = "csv",
  pattern = "^filename.*",
  fn_column = TRUE,
  save = TRUE,
  fn_output = NULL,
  save_dir = getwd(),
  par = FALSE
)

## End(Not run)

jeksterslabds/jeksterslabRutils documentation built on Jan. 18, 2021, 11:41 p.m.