Learn R Programming

berryFunctions (version 1.11.0)

combineFiles: Combine Textfiles into one

Description

Combine several textfiles into one, regardless of their content.

Usage

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

Arguments

inFiles
vector with names of input files, as can be read with scan. Is pasted with inDir, so don't use full paths. DEFAULT: dir()
inDir
Character string: path to the files. E.g. "D:/MyFolder/Subfolder". Don't have / at the end. DEFAULT: getwd().
outFile
Character string: name of the file to be created. Again, just the file name, not a path. DEFAULT: "combined_Textfiles.txt"
outDir
Character string: path for output file. DEFAULT: inDir
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

Value

None, but prints number of files combined and output file name.

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)
## 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)

Run the code above in your browser using DataLab