r - getURL (from RCurl package) doesn't work in a loop -
i have list of url named urllist , loop on source code each of url :
for (k in 1:length(urllist)){ temp = geturl(urllist[k]) }
problem random url, code stuck , error message:
error in function (type, msg, aserror = true) : transfer closed outstanding read data remaining
but when try geturl function, not in loop, url had problem, works.
any please ? thank
hard tell sure without more information, requests getting sent quickly, in case pausing between requests :
for (k in 1:length (urllist)) { temp = geturl (urllist[k]) sys.sleep (0.2) }
i'm assuming actual code 'temp' before writing on in every iteration of loop, , whatever fast.
you try building in error handling 1 problem doesn't kill whole thing. here's crude example tries twice on each url before giving up:
for (url in urllist) { temp = try (geturl (url)) if (class (temp) == "try-error") { temp = try (geturl (url)) if (class (temp) == "try-error") temp = paste ("error accessing", url) } sys.sleep(0.2) }
Comments
Post a Comment