R/k_imgMoveFiles.R

Defines functions k_imgMoveFiles

Documented in k_imgMoveFiles

#' Image Move files
#'
#' Moves files into directories previously created with k_imgDirSetup
#'
#' @param directory Parent directory of label folders
#' @param files filenames of files to be moved
#' @param labels Labels of the files to be moved into appropriate folder. Labels should match folder names
#' @param train_id binary indicator saying whether the datapoint is training or testing (Train == 1)
#' @param delete Logical saying whether or not to deleter the file after copy.
#' @return Returns NULL
#' @export


k_imgMoveFiles <- function(directory, files, labels, train_id, delete = FALSE){
  
  for (i in 1:length(files)) {
    
    if (file.copy(from = paste0(directory, files[i]),
                  to = paste0(
                    directory, 
                    ifelse(as.numeric(train_id[i]) == 1,
                           "train/",
                           "test/"),
                    labels[i], "/", files[i]
                  ), 
                  overwrite = TRUE)) {
      
      if (delete) unlink(paste0(directory, files[i])) # Deletes file if copy was successful & delete == false
      
    }
  }
}
blazickjoe/DataScienceLibrary documentation built on Nov. 5, 2019, 2:26 p.m.