R/loadData.R

Defines functions .loadData

Documented in .loadData

.loadData<-function(dirname=NULL,svn_path=NULL){
  ####################################################################
  #Check if the repository is available under svn_path
  ###################################################################
  svn_paths<-c(svn_path,"http://localhost:8888/svn/magpie/libraries/","http://subversion/svn/magpie/libraries/","not_found")
  for(svn_path in svn_paths){
    if(length(suppressWarnings(system(paste("svn ls",svn_path),intern=T,ignore.stderr=T)))>0) break
  }
  if(svn_path=="not_found") stop("Unable to connect to the repository. Check your svn path and internet connection.")
  
  ###################################################################
  #checkout the library to incorporate the new data
  ###################################################################
  if(is.null(dirname)) dirname<-paste("lib",gsub(":","-",gsub(" ","",Sys.time())),sep="")
  thisdir<-getwd()
  if(system(paste("svn checkout",svn_path,dirname,"--depth empty"))!=0){
    stop("Problems downloading the library from the repository. Maybe a wrong svn_path specified?")
  }
  setwd(dirname)
  if(system("svn up validation")!=0){
    .cleanDownload(libdir=dirname,workdir=thisdir)
    stop("Problems downloading the library from the repository. Maybe a wrong svn_path specified?")
  }
  setwd(thisdir)
  ###################################################################
  #Load the downloaded valdata object as well as the mapping oject
  ###################################################################
  load(path(dirname,"validation/data/valdata.rda"))
  load(path(dirname,"validation/data/mapping.rda"))
  assign("valdata",valdata,pos=sys.frame(sys.parent(n=1)))
  assign("mapping",mapping,pos=sys.frame(sys.parent(n=1)))
  return(dirname)
}
pik-piam/validation documentation built on Nov. 5, 2019, 12:50 a.m.