cbindFiles {Haplin}R Documentation

Combine a sequence of files by columns

Description

Takes a sequence of files and combines them column-wise (side-by-side), i.e. reads each file line by line, pastes corresponding lines, then writes to outfile. Combining files line by line is especially useful when working with large datasets, where the reading of entire files may be time consuming and require a large amount of memory.

Usage

cbindFiles(infiles, outfile, col.sep, ask = TRUE, verbose = TRUE)

Arguments

infiles

A character vector of names (and paths) of the files to combine.

outfile

A character string giving the name of the resulting file. The name of the file is relative to the current working directory, unless the file name contains a definite path.

col.sep

Specifies the column separator which will be inserted between files.

ask

Logical. Default is "TRUE". If set to "FALSE", an already existing outfile will be overwritten without asking.

verbose

Logical. Default is "TRUE", which means that the line number is displayed for each iteration, i.e. each combined line.

Details

The function cbind combines R objects by columns. However, reading large datafiles may require a large amount of memory and be extremely time consuming. cbindFiles combines the files column-wise, one line at a time, and then writes each line to outfile. This avoids reading the full files into memory.
If infiles contains only one file, this file will be copied directly to outfile, i.e. without any line-by-line modifications.

Value

There is no useful output; the objective of cbindFiles is to produce outfile.

Author(s)

Miriam Gjerdevik,
with Hakon K. Gjessing
Professor of Biostatistics
Division of Epidemiology
Norwegian Institute of Public Health
hakon.gjessing@uib.no

References

Web Site: https://haplin.bitbucket.io

See Also

rbindFiles, lineByLine

Examples

## Not run: 

# Combines the three infiles side-by-side
cbindFiles(infiles = c("myfile1.txt", "myfile2.txt", 
"myfile3.txt"), outfile = "myfile_combined_by_columns.txt", 
col.sep = " ", ask = TRUE, verbose = TRUE)


## End(Not run)

[Package Haplin version 7.3.1 Index]