R/ProcessFiles_ARIS.R

Defines functions ProcessFiles_ARIS

Documented in ProcessFiles_ARIS

#' Processes all ARIS files within a specified directory.
#' @description Reads all the files in the passed directory and appends them into one data frame.  This is the only function called by the user to read ARIS data. The function calls \code{\link{ReadFile_ARIS}} internally to read individual sonar files. Sometimes the function will error out because of a bad text file - just remove the offending file (look at the text file first, to make sure that it is empty) and the function should run after that.
#' @param dir Full address of the directory to be processed.
#' @author Allison Matter and Carl Pfisterer.
#' @export

ProcessFiles_ARIS = function(dir){
  cat(paste("\nProcessing files in directory:",dir,"\n"));
  files = list.files(dir,pattern=".txt$",full.names=TRUE);  #Only read files ending in .txt
  if(length(files) > 0){
    progress = txtProgressBar(style=3,min=0,max=length(files),initial=0);
    cnt = 0;
    for(file in files){
      # cat("File: ",file,"\n");
      Data = ReadFile_ARIS(file);
      if(cnt==0){
        AllData = list(Data);
      }
      else{
        AllData = append(AllData,list(Data));   #Append to list of data
      }
      cnt = cnt+1;
      if((cnt%%20) == 0) setTxtProgressBar(progress,value=cnt); #Update every 20 files
    }
    AllData = do.call(rbind, AllData);   #Merge data from all files into one data frame
  }
  else{
    AllData = NA;         #Return NA if there are no files in the directory
  }
  AllData
}
jBernardADFG/ChenaSalchaTowerSonar documentation built on Oct. 11, 2020, 1 a.m.