Learn R Programming

berryFunctions (version 1.22.5)

combineFiles: 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,
  ...
)

Value

Final output file, invisibly.

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.

Author

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

Run this code

## These are skipped by rcmd check (writing to external places is not allowed)
if (FALSE) {
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"))
}

Run the code above in your browser using DataLab