R または RCurl パッケージに、Web ページが指定された期間を超えた場合に Web ページのダウンロードをあきらめて、次のコード行に移動するように指示する方法はありますか? 例えば:
> library(RCurl)
> u = "http://photos.prnewswire.com/prnh/20110713/NY34814-b"
> getURL(u, followLocation = TRUE)
> print("next line") # programme does not get this far
これは私のシステムでハングアップし、最終行に進みません。
編集:以下の@Richie Cottonの回答に基づいて、私が望むものを「ある程度」達成することはできますが、なぜ予想よりも時間がかかるのかわかりません。たとえば、次のようにすると、RGUI で [Misc >> Buffered Output] オプションを選択または選択解除するまで、システムがハングします。
> system.time(getURL(u, followLocation = TRUE, .opts = list(timeout = 1)))
Error in curlPerform(curl = curl, .opts = opts, .encoding = .encoding) :
Operation timed out after 1000 milliseconds with 0 out of 0 bytes received
Timing stopped at: 0.02 0.08 ***6.76***
解決策: 以下の @Duncan の投稿に基づいて、その後 curl ドキュメントを調べたところ、次のように maxredirs オプションを使用して解決策を見つけました。
> getURL(u, followLocation = TRUE, .opts = list(timeout = 1, maxredirs = 2, verbose = TRUE))
よろしくお願いします。
トニー・ブレイアル
O/S: Windows 7
R version 2.13.0 (2011-04-13) Platform: x86_64-pc-mingw32/x64 (64-bit)
attached base packages:
[1] stats graphics grDevices utils
datasets methods base
other attached packages:
[1] RCurl_1.6-4.1 bitops_1.0-4.1
loaded via a namespace (and not attached):
[1] tools_2.13.0