EVOLUTION-MANAGER
Edit File: getURIAsynchronous.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Download multiple URIs concurrently, with inter-leaved...</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for getURIAsynchronous {RCurl}"><tr><td>getURIAsynchronous {RCurl}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Download multiple URIs concurrently, with inter-leaved downloads</h2> <h3>Description</h3> <p>This function allows the caller to specify multiple URIs to download at the same time. All the requests are submitted and then the replies are processed as data becomes available on each connection. In this way, the responses are processed in an inter-leaved fashion, with a chunk from one response from one request being processed and then followed by a chunk from a different request. </p> <p>Downloading documents asynchronously involves some trade-offs. The switching between different streams, detecting when input is available on any of them involves a little more processing and so increases the consumption of CPU cycles. On the other hand, there is a potentially large saving of time when one considers total time to download. See <a href="http://www.omegahat.net/RCurl/concurrent.xml">http://www.omegahat.net/RCurl/concurrent.xml</a> for more details. This is a common trade-off that arises in concurrent/parallel/asynchronous computing. </p> <p><code><a href="getURL.html">getURI</a></code> calls this function if more than one URI is specified and <code>async</code> is <code>TRUE</code>, the default in this case. One can also download the (contents of the) multiple URIs serially, i.e. one after the other using <code><a href="getURL.html">getURI</a></code> with a value of <code>FALSE</code> for <code>async</code>. </p> <h3>Usage</h3> <pre> getURIAsynchronous(url, ..., .opts = list(), write = NULL, curl = getCurlHandle(), multiHandle = getCurlMultiHandle(), perform = Inf, .encoding = integer(), binary = rep(NA, length(url))) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>url</code></td> <td> <p>a character vector identifying the URIs to download.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>named arguments to be passed to <code><a href="curlSetOpt.html">curlSetOpt</a></code> when creating each of the different <code>curlHandle</code> objects.</p> </td></tr> <tr valign="top"><td><code>.opts</code></td> <td> <p>a named list or <code>CURLOptions</code> object identifying the curl options for the handle. This is merged with the values of ... to create the actual options for the curl handle in the request.</p> </td></tr> <tr valign="top"><td><code>write</code></td> <td> <p>an object giving the functions or routines that are to be called when input is waiting on the different HTTP response streams. By default, a separate callback function is associated with each input stream. This is necessary for the results to be meaningful as if we use a single reader, it will be called for all streams in a haphazard order and the content interleaved. One can do interesting things however using a single object. </p> </td></tr> <tr valign="top"><td><code>curl</code></td> <td> <p>the prototypical curlHandle that is duplicated and used in in </p> </td></tr> <tr valign="top"><td><code>multiHandle</code></td> <td> <p>this is a curl handle for performing asynchronous requests. </p> </td></tr> <tr valign="top"><td><code>perform</code></td> <td> <p>a number which specifies the maximum number of calls to <code><a href="curlPerform.html">curlMultiPerform</a></code> that are to be made in this function call. This is typically either 0 for no calls or <code>Inf</code> meaning process the requests until completion. One may find alternative values useful, such as 1 to ensure that the requests are dispatched. </p> </td></tr> <tr valign="top"><td><code>.encoding</code></td> <td> <p>an integer or a string that explicitly identifies the encoding of the content that is returned by the HTTP server in its response to our query. The possible strings are ‘UTF-8’ or ‘ISO-8859-1’ and the integers should be specified symbolically as <code>CE_UTF8</code> and <code>CE_LATIN1</code>. Note that, by default, the package attempts to process the header of the HTTP response to determine the encoding. This argument is used when such information is erroneous and the caller knows the correct encoding. </p> </td></tr> <tr valign="top"><td><code>binary</code></td> <td> <p>a logical vector identifying whether each URI has binary content or simple text.</p> </td></tr> </table> <h3>Details</h3> <p>This uses <code><a href="curlPerform.html">curlMultiPerform</a></code> and the multi/asynchronous interface for libcurl. </p> <h3>Value</h3> <p>The return value depends on the run-time characteristics of the call. If the call merely specifies the URIs to be downloaded, the result is a named character vector. The names identify the URIs and the elements of the vector are the contents of the corresponding URI. </p> <p>If the requests are not performed or completed (i.e. <code>perform</code> is zero or too small a value to process all the chunks) a list with 2 elements is returned. These elements are: </p> <table summary="R valueblock"> <tr valign="top"><td><code>multiHandle</code></td> <td> <p>the curl multi-handle, of class <code><a href="MultiCURLHandle-class.html">MultiCURLHandle-class</a></code>. This can be used in further calls to <code><a href="curlPerform.html">curlMultiPerform</a></code></p> </td></tr> <tr valign="top"><td><code>write</code></td> <td> <p>the <code>write</code> argument (after it was potentially expanded to a list). This can then be used to fetch the results of the requests when the requests are completed in the future. </p> </td></tr> </table> <h3>Author(s)</h3> <p>Duncan Temple Lang <duncan@r-project.org></p> <h3>References</h3> <p>Curl homepage <a href="http://curl.haxx.se">http://curl.haxx.se</a></p> <h3>See Also</h3> <p><code><a href="getURL.html">getURL</a></code> <code><a href="getCurlHandle.html">getCurlMultiHandle</a></code> <code><a href="curlPerform.html">curlMultiPerform</a></code> </p> <h3>Examples</h3> <pre> uris = c("http://www.omegahat.net/RCurl/index.html", "http://www.omegahat.net/RCurl/philosophy.xml") txt = getURIAsynchronous(uris) names(txt) nchar(txt) </pre> <hr /><div style="text-align: center;">[Package <em>RCurl</em> version 1.98-1.2 <a href="00Index.html">Index</a>]</div> </body></html>