R/assignBar.R

#' Function that makes prompts to get required columns for bulk upload file 
#' 
#' @export
#' @param df The manifest file 
#' 
#' @return A bulk upload file template
#' 
#' @examples
#' new.df <- assignBar(new.df)

assignBar <- function(new.df){
  # ask if there's an old barcode.  if not, assign new.
  old <- askYesNo('Is there an old barcode for these samples?')
  if(old){
    old_bar <- readline('What is the column with the old barcodes called? ')
    barcode <- as.data.frame(new.df[,grep(paste0('\\b', old_bar, '\\b'), colnames(new.df))])
    new.df$Barcode <- barcode
  } else{
    # last_bar <- 1234567890 
    new.df$Barcode <- NA
    last_bar <- as.numeric(readline('What was the last barcode used? '))
    arking_bar <- 'A'
    for(i in 1:nrow(new.df))
    {
      last_bar <- last_bar + 1
      barcode <- paste0(arking_bar, last_bar)
      new.df$Barcode[i] <- barcode
    }
  }
  return(new.df)
}
syyang93/openSpec documentation built on May 16, 2019, 3:24 p.m.