在另一个函数

时间:2017-05-15 14:27:54

标签: r

我正在调整GitHub(https://github.com/PeterDSteinberg/RSWMM)的开源代码来校准EPA-SWMM。代码分为两部分 - RSWMM.r包含查找/替换SWMM值所需的函数,读入校准文件等.runRSWMM.r是一个包含调用相关RSWMM函数的优化代码的包装器。我需要编辑RSWMM代码以读取.txt文件并编写以下代码来执行此操作。

getLIDtimeseriesFromTxt <- function(TxtFile, dateformat = "%m/%d/%y %H:%M"){
  #RW (05/12/17): This function added to read in the appropriate CSV file 
  #containing the LID outputs
  library(chron)
  LID_data <- read.table(TxtFile, skip=9)
  times <- LID_data[,1]
  startTime <- as.chron("6/8/2006 1:00", format="%m/%d/%Y %H:%M", tz="GMT") #M/D/YY H:MM
  simData <<- {}
  simData$times <<- (times/24)+startTime
  simData$obs <<- LID_data[,9] #the ninth column is ponding depth
  return(simData)
}

getCalDataFromCSV<-function(CSVFile,dateFormat="%m/%d/%y %H:%M"){

   temp=read.csv(file=CSVFile, header = TRUE, sep = ",", quote="\"", dec=".", fill = TRUE, comment.char="",stringsAsFactors = FALSE)
   calData<<-{}
   #RW (05/12/17): This line of code edited to match the date format pulled in from the simulation file. 
   calData$times<<-as.chron(temp[,1], format=dateFormat,tz="GMT")
   calData$obs<<-temp[,2]
   return(calData)
}

interpCalDataToSWMMTimes<-function(){
  mergedData <- merge(simData, calData, by="times")
  return(mergedData)
  #first column of mergedData are times as chrons,
  #second column is simulated data
  #third column is observed data
}

当我从runRSWMM运行完整代码时,我得到的错误是找不到“simData”,这意味着我不能使用merge。但是,这似乎不是变量“calData”的问题,我可以在RStudio的全局环境中看到它。这两个变量的输出方式有何不同?我该如何解决这个错误?

0 个答案:

没有答案