combineFiles: Combine Textfiles into one

View source: R/combineFiles.R

combineFilesR Documentation

Combine Textfiles into one

Description

Combine several textfiles into one, regardless of their content.

Usage

combineFiles(
  inFiles = dir(),
  outFile = "combined_Textfiles.txt",
  overwrite = FALSE,
  sep = NULL,
  names = TRUE,
  selection = NULL,
  progbar = !quiet,
  quiet = FALSE,
  ...
)

Arguments

inFiles

vector with names of input files, as can be read with scan. DEFAULT: dir()

outFile

Character string: name of the file to be created. Passed to newFilename. DEFAULT: "combined_Textfiles.txt"

overwrite

Logical: overwrite outFile? DEFAULT: FALSE

sep

Character string: Separation between content of each file and the following. DEFAULT: NULL, with which it uses an empty line, two lines with dashes, and another line break.

names

Should File names be included after sep? DEFAULT: TRUE

selection

Index of rows that should be written. Can refer to each file separately, e.g. substr(inFile_i,1,1)=="#". DEFAULT: all lines

progbar

Should a progress bar be drawn? Useful if you combine many large files. DEFAULT: !quiet, i.e. TRUE

quiet

Suppress message about number of files combined? DEFAULT: FALSE

...

Arguments passed to scan, but not one of: file, what, blank.lines.skip, sep, quiet.

Value

Final output file, invisibly.

Author(s)

Berry Boessenkool, berry-b@gmx.de, Nov 2012, Dec 2014, Jul 2015

See Also

compareFiles, and the functions used internally here, namely: paste, scan, write.

Examples


## These are skipped by rcmd check (writing to external places is not allowed)
## Not run: 
cat("This is Sparta.\nKicking your face.", file="BujakashaBerry1.txt")
cat("Chuck Norris will roundhousekick you.", file="BujakashaBerry2.txt")
combineFiles(inFiles=paste0("BujakashaBerry", 1:2, ".txt"),
             outFile="BujakashaBerry3.txt")
file.show("BujakashaBerry3.txt")
unlink(paste0("BujakashaBerry", 1:3, ".txt"))

## End(Not run)


brry/berryFunctions documentation built on Feb. 21, 2024, 2:20 p.m.