Debian Codegraph @

man/chunkToLineReader.Rd

raw
1 \name{chunkToLineReader}
2 \alias{chunkToLineReader}
3 \title{Utility that collects data from the HTTP reply into lines and
4 calls user-provided function.
5 }
6 \description{
7 When one provides an R function to process the body of
8 the R rep
9 }
10 \usage{
11 chunkToLineReader(f, verbose = FALSE)
12 }
13 %- maybe also 'usage' for other objects documented here.
14 \arguments{
15 \item{f}{a function that is to be called each time
16 the \code{read} function is invoked and there are complete
17 lines in that input.}
18 \item{verbose}{a logical value. If \code{TRUE},
19 information is displayed when there is any text
20 that does not form a complete line and is held
21 for processing in the next chunk.
22 }
23 }
24 \details{
25 This constructs a closure and then processes each chunk as
26 they are passed to the read function.
27 It strips away any text that does not form a complete line
28 at the end of the chunk and holds this to be added to the next chunk
29 being processed.
30 }
31 \value{
32 A list with two components
33 \item{read}{the function that will do the actual reading from the
34 HTTP response stream and call the function \code{f} on each
35 step (assuming the chunk has a line marker.}
36 \item{comp2 }{Description of 'comp2'}
37 ...
38 }
39 \references{Curl homepage \url{https://curl.se/}}
40 \author{Duncan Temple Lang}
41
42 \seealso{
43 \code{\link{getURI}} and the \code{write} argument.
44 \code{\link{getForm}}, \code{\link{postForm}}
45 \code{\link{curlPerform}}
46 }
47 \examples{
48 # Read a rectangular table of data into R from the URL
49 # and add up the values and the number of values read.
50
51 summer =
52 function()
53 {
54 total = 0.0
55 numValues = 0
56
57 list(read = function(txt) {
58 con = textConnection(txt)
59 on.exit(close(con))
60 els = scan(con)
61 numValues <<- numValues + length(els)
62 total <<- total + sum(els)
63
64 ""
65 },
66 result = function() c(total = total, numValues = numValues))
67 }
68
69 s = summer()
70
71 tryCatch(
72 getURL("https://aitap.grebedoc.dev/RCurl/matrix.data", write = chunkToLineReader(s$read)$read),
73 GenericCurlError = identity
74 )
75 }
76 \keyword{IO}
77 \concept{Web}
78 \concept{HTTP}
79