Learn R Programming

berryFunctions (version 1.4)

combineTextfiles: combine several Textfiles into one

Description

Combine several textfiles into one, regardless of their content.

Usage

combineTextfiles(inFiles, inDir=getwd(),
outFile="combined_Textfiles.txt", outDir=inDir, sep=NULL)

Arguments

inFiles
vector with names of input files, as can be read with scan. Is pasted with inDir, so don't use full paths.
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.

Value

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

See Also

paste, scan, write, cat.

Examples

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

Run the code above in your browser using DataLab