R/stick.R

#' stick two ascii exported data into one
#'
#' This function reads in two ascii files and save single one
#'
#' @param files lists of filenames
#' @param first.row
#' @param last.row
#' @param replace
#'
#' @keywords stick
#' @export
#' @examples
#' stick(list('file1.txt', 'file2.txt'))
stick <- function(files, first.row = 'XYDATA', last.row = '##### Extended Information', replace = F) {
  data <- do.call(rbind, lapply(files, function(ascii.file, first.row, last.row){
    readin(ascii.file)
  }))

  data <- rbind(first.row, data, last.row)

  write.table(
    data,
    file = paste0(dirname(files[[1]]), '/',
                  strsplit(basename(files[[1]]), '\\.')[[1]][[1]],
                  '-sticked.txt'),
    row.names = F,
    col.names = F,
    quote = F, sep = '\t'
  )

  if (replace) {
        lapply(files, unlink)
  }
}
yanxianUCSB/jascor documentation built on May 21, 2019, 3:04 a.m.