Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

chunkToLineReader

Utility that collects data from the HTTP reply into lines and calls user-provided function.


Description

When one provides an R function to process the body of the R rep

Usage

chunkToLineReader(f, verbose = FALSE)

Arguments

f

a function that is to be called each time the read function is invoked and there are complete lines in that input.

verbose

a logical value. If TRUE, information is displayed when there is any text that does not form a complete line and is held for processing in the next chunk.

Details

This constructs a closure and then processes each chunk as they are passed to the read function. It strips away any text that does not form a complete line at the end of the chunk and holds this to be added to the next chunk being processed.

Value

A list with two components

read

the function that will do the actual reading from the HTTP response stream and call the function f on each step (assuming the chunk has a line marker.

comp2

Description of 'comp2'

...

Author(s)

Duncan Temple Lang

References

Curl homepage http://curl.haxx.se

See Also

getURI and the write argument. getForm, postForm curlPerform

Examples

# Read a rectangular table of data into R from the URL
# and add up the values and the number of values read.

summer =
function()
{
  total = 0.0
  numValues = 0

  list(read = function(txt) {
                 con = textConnection(txt)
                 on.exit(close(con))
                 els = scan(con)
                 numValues <<- numValues + length(els)
                 total <<- total + sum(els)

                 ""
              },
       result = function() c(total = total, numValues = numValues))
}

s = summer()

if(url.exists("http://www.omegahat.net/RCurl/matrix.data"))
   getURL("http://www.omegahat.net/RCurl/matrix.data", write = chunkToLineReader(s$read)$read)

RCurl

General Network (HTTP/FTP/...) Client Interface for R

v1.98-1.3
BSD_3_clause + file LICENSE
Authors
CRAN Team [ctb, cre] (de facto maintainer since 2013), Duncan Temple Lang [aut] (<https://orcid.org/0000-0003-0159-1546>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.