R/merge_synthetic_library.R

Defines functions merge_synthetic_library

merge_synthetic_library <- function(syntheticLibrary1, syntheticLibrary2){
  
  if(class(syntheticLibrary1) != "syntheticLibrary" | class(syntheticLibrary2) != "syntheticLibrary" )
    stop("At least one input is not a synthetic library generated by SynthEx!")
  
  if(syntheticLibrary1$interval != syntheticLibrary2$interval |
       nrow(syntheticLibrary1$Bins) != nrow(syntheticLibrary2$Bins))
    stop("Two synthetic libraries should have the same bin size!")
  
  new_syntheticLibrary <- NULL
  
  new_syntheticLibrary$Protocol <- append(syntheticLibrary1$Protocol, syntheticLibrary2$Protocol) 
  new_syntheticLibrary$Bins <- syntheticLibrary1$Bins
  new_syntheticLibrary$NumProtocol <- syntheticLibrary1$NumProtocol + syntheticLibrary2$NumProtocol
  new_syntheticLibrary$interval <- syntheticLibrary1$interval
  
  class(new_syntheticLibrary) <- "syntheticLibrary"

  return(new_syntheticLibrary)
}
ChenMengjie/SynthEx documentation built on Oct. 1, 2020, 8:45 a.m.