# 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 (FALSE) {
## broken, 2022-07-29
if(url.exists("https://www.omegahat.net/RCurl/matrix.data"))
getURL("https://www.omegahat.net/RCurl/matrix.data", write = chunkToLineReader(s$read)$read)
}
Run the code above in your browser using DataLab