cbindFiles | R Documentation |
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.
cbindFiles(infiles, outfile, col.sep, ask = TRUE, verbose = TRUE)
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. |
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.
There is no useful output; the objective of cbindFiles
is to produce outfile
.
Miriam Gjerdevik,
with Hakon K. Gjessing
Professor of Biostatistics
Division of Epidemiology
Norwegian Institute of Public Health
hakon.gjessing@uib.no
Web Site: https://haplin.bitbucket.io
rbindFiles
, lineByLine
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.