File: chunkToLineReader.Rd

package info (click to toggle)
r-cran-rcurl 1.95-4.8-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,140 kB
  • ctags: 515
  • sloc: ansic: 3,135; xml: 1,734; asm: 993; sh: 12; makefile: 2
file content (77 lines) | stat: -rw-r--r-- 2,219 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
\name{chunkToLineReader}
\alias{chunkToLineReader}
\title{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)
}
%- maybe also 'usage' for other objects documented here.
\arguments{
  \item{f}{a function that is to be called each time
    the \code{read} function is invoked and there are complete
    lines in that input.}
  \item{verbose}{a logical value. If \code{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
  \item{read}{the function that will do the actual reading from the
    HTTP response stream and call the function \code{f} on each
    step (assuming the chunk has a line marker.}
  \item{comp2 }{Description of 'comp2'}
  ...
}
\references{Curl homepage \url{http://curl.haxx.se}}
\author{Duncan Temple Lang <duncan@wald.ucdavis.edu>}

\seealso{
  \code{\link{getURI}} and the \code{write} argument.
  \code{\link{getForm}}, \code{\link{postForm}}  
  \code{\link{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)
}
\keyword{IO}
\concept{Web}
\concept{HTTP}