R/GADM1prep.R

#' Formats and prepares GADM1 located vaccination campaigns
#'
#' @param vc.GADM1 Cleaned GADM1 campaigns
#' @examples
#' GADM1prep(cleaned$vc.GADM1)
#' @keywords internal


GADM1prep<-function(vc.GADM1){
  
  #Extract columns we want
  cols.out<-c("vac.id", "year", "country", "country.code", 
               "adm2.prop", "target.population", "doses", "coverage.planned", "coverage.adm", 
               "coverage.survey", "agemin", "agemax", "campaign.type", "scenario", "skew","location.encoding")
  
  if(dim(vc.GADM1)[1]>0){
    
    #Match the columns with what we have
    mm<-match(cols.out, names(vc.GADM1))
    
    #Generate a csv to output vaccination campaigns in a better format
    #This uses the functions 'pull.vc.out' and 'separate.locations' to
    #create a matrix of campaigns with the details we want
    vc.out.GADM1<-NULL
    
    suppressWarnings(for(i in seq_len(nrow(vc.GADM1))) vc.out.GADM1<-rbind(vc.out.GADM1, pull.vc.out(vc.GADM1[i, ], mm)))
    
    # #Remove duplicate columns
    # vc.out.GADM1<-vc.out.GADM1[,which(!duplicated(names(vc.out.GADM1)))]
    
    #Set the proportion of adm2 coverage to NA - currently only using adm1
    vc.out.GADM1$adm2.prop<-NA
    
    #Sets the level of adm values
    lvlGADM1<-rep(3, nrow(vc.out.GADM1))
    lvlGADM1[is.na(vc.out.GADM1$adm3)]<-2
    lvlGADM1[is.na(vc.out.GADM1$adm2)]<-1
    lvlGADM1[is.na(vc.out.GADM1$adm1)]<-0
    vc.out.GADM1
  } 
  
}
arranhamlet/popvac_package documentation built on May 10, 2019, 1:48 p.m.