source('src/datavalidator.R')

dummyplot<-function(text='An error was found in the data, please check error logs'){
  plot(c(0,1),c(0,1),axes=FALSE, xlab='', ylab='' , type='n')
  box()
  text(.5,.5,labels=text)
}

plotit<-function(fil){
  wrap<-function(expr){
    tryCatch(expr,error=function(e){E<<-e})
  }
  if(file.exists(fil)){
    basename<-sub('\\..*$','',fil)
    png(filename = paste(basename,".png", sep=""), width = 600, height = 600, units = "px", pointsize = 10, bg = "white")    
      E<-NULL
      if(is.null(E)){
      dat<-read.table(fil)
      plot(dat,xlab='x',ylab='y') 
      }else{dummyplot()}
    dev.off() 
  }
}

owd<-getwd()
setwd('data')
plotit('linreg.dat')
setwd(owd)


