[英]How to write trycatch for this scenario in R
Currently I have written the ifelse statement to get the correct symbol pattern.目前我已经编写了 ifelse 语句来获得正确的符号模式。 But I want to know how I can write tryCatch for this statement?但我想知道如何为这条语句编写 tryCatch ? Because sometimes getSymbols returns error if symbol doesn't have correct extension.因为如果符号没有正确的扩展名,有时 getSymbols 会返回错误。
getSymbols(
ifelse(
substring(stocksList[i,1],1,1) == "^" | grepl(".BO", stocksList[i,1]),
stocksList[i,1] ,
paste0(stocksList[i,1], ".NS")
),
from = fromDate,
to = toDate,
periodicity = freqStr ,
return.class = 'zoo',
env = NULL
)
Have you tried wrapping the complete code inside tryCatch
?您是否尝试过将完整的代码包装在tryCatch
?
tryCatch({
getSymbols(ifelse(
substring(stocksList[i,1],1,1) == "^" | grepl(".BO", stocksList[i,1]),
stocksList[i,1] ,
paste0(stocksList[i,1] , ".NS")
),
from = fromDate,
to = toDate,
periodicity = freqStr ,
return.class = 'zoo',
env = NULL)
},
error = function(e) message('Cannot download the data')
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.