问题描述
我正在尝试使用 R 的 dataRetrieval
包从 USGS 网站下载数据。
为此,我在 R 中生成了一个名为 getstreamflow
的函数,例如,当我运行时它可以正常工作。
siteNumber <- c("094985005","09498501","09489500","09489499","09498502")
Streamflow = getstreamflow(siteNumber)
我可以在下载数据没有问题的情况下运行该功能,但对于某些站点,我收到以下错误:
Request failed [404]. Retrying in 1.1 seconds...
Request failed [404]. Retrying in 3.3 seconds...
For: https://waterservices.usgs.gov/nwis/site/?siteOutput=Expanded&format=rdb&site=0946666666
为避免函数在遇到错误时停止,我尝试使用 tryCatch
,如下代码所示:
Streamflow = tryCatch(
expr = {
getstreamflow(siteNumber)
},error = function(e) {
message(paste(siteNumber," there was an error"))
})
我希望函数在遇到错误时跳过该站并转到下一个。目前,我得到的输出是下面显示的输出,这显然是错误的,因为它说所有站都存在错误:
094985005 there was an error09498501 there was an error09489500 there was an error09489499 there was an error09498502 there was an error09511300 there was an error09498400 there was an error09498500 there was an error09489700 there was an error09500500 there was an error09489082 there was an error09510200 there was an error09489100 there was an error09490500 there was an error09510180 there was an error09494000 there was an error09490000 there was an error09489086 there was an error09489089 there was an error09489200 there was an error09489078 there was an error09510170 there was an error09493500 there was an error09493000 there was an error09498503 there was an error09497500 there was an error09510000 there was an error09509502 there was an error09509500 there was an error09492400 there was an error09492500 there was an error09497980 there was an error09497850 there was an error09492000 there was an error09497800 there was an error09510150 there was an error09499500 there was an error... <truncated>
我在使用 tryCatch
时做错了什么?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)