R/assignDummy.R

#' Function that creates blank columns that openSpecimen has to have....
#' Requires that you be mounted to jhpce! Needs this file 'dcs01/arking/arkinglab/resources/openSpec/colnames.rds' in order to work
#' 
#' @export
#' @param new.df The finished file, after running getLoc(), getRequiredFields(), and assignBar()
#' 
#' @return A bulk upload file template.  BE WARY YOU WILL NOT BE ABLE TO VIEW THIS IN RSTUDIO.
#' 
#' @examples
#' new.df <- assignDummy(new.df)

assignDummy <- function (new.df) 
{
  load("/Users/arkinglab/jhpce/dcs01/arking/arkinglab/resources/openSpec/colnames.rds")
  load("/Users/arkinglab/jhpce/dcs01/arking/arkinglab/resources/openSpec/colnames_noperiods.rds")
  '%!in%' <- function(x,y)!('%in%'(x,y))
  colnames(new.df) <- make.names(colnames(new.df))
  
  # get rid of columns that shouldn't be there
  new.df[,which((colnames(new.df)) %!in% bulk_upload_columns)] <- NULL
  
  missing.columns <- bulk_upload_columns[which(bulk_upload_columns %!in% colnames(new.df))]
  
  # initialize columns that should exist
  new.df[, missing.columns] <- ''
  
  reordered <- new.df[bulk_upload_columns]
  colnames(reordered) <- bulk_upload_columns_noperiods
  
  return(reordered)
}
syyang93/openSpec documentation built on May 16, 2019, 3:24 p.m.