go <- T
while(go){
test <- tryCatch({aMNLFA.sample(ob)
aMNLFA.initial(ob)
line <- "[IBR14$1-IBR14$8];
[IBR21$1-IBR21$8];
[IBR25$1-IBR25$4];"
filenames = list("meanimpactscript.inp", "varimpactscript.inp", "measinvarscript_IBR14.inp", "measinvarscript_IBR21.inp", "measinvarscript_IBR25.inp")
for (i in filenames) {
txt <- readLines(i)
ix <- grep("ETA BY IBR25", txt)
p <- paste(append(txt, line, ix), collapse = "\n")
writeLines(p, con=i)}
runModels(filenames)
}, warning= function(w) return("repeat"))
if(typeof(test)!="character"){
go <- F
}else{
if(test!="repeat"){
go <- F
}
}
}
runModels(filenames)
可重现示例:
testfunc <- function(x){
if(x!=10){
warning("not 10")
}
return(x)
}
go <- T
count=0
while(go){
test <- tryCatch({
count=count+1
testfunc(count)
}, warning= function(w) return("repeat"))
if(typeof(test)!="character"){
go <- F
}else{
if(test!="repeat"){
go <- F
}
}
}
> count
[1] 10
> test
[1] 10
1条答案
按热度按时间pengsaosao1#
使用
tryCatch
捕获错误可重现示例: