binaryBuffer | R Documentation |
This is the constructor function for creating an internal data
structure
that is used when reading binary data from an HTTP request
via RCurl. It is used with the native routine
R_curl_write_binary_data
for collecting
the response from the HTTP query into a buffer that stores
the bytes. The contents can then be brought back into R
as a raw
vector and then used in different ways,
e.g. uncompressed with the Rcompression
package,
or written to a file via writeBin
.
binaryBuffer(initialSize = 5000)
initialSize |
a number giving the size (number of bytes) to
allocate for the buffer. In most cases, the size won't make an
enormous difference. If this is small, the
|
An object of class RCurlBinaryBuffer
which is to be treated
as an opaque data for the most part. When passing this as the value of
the file
option, one will have to pass the ref slot.
After the contents have been read, one can convert this object to an R
raw vector using as(buf, "raw")
.
Duncan Temple Lang
Curl homepage https://curl.se/
R_curl_write_binary_data
if(url.exists("https://www.omegahat.net/RCurl/xmlParse.html.gz")) {
buf = binaryBuffer()
# Now fetch the binary file.
getURI("https://www.omegahat.net/RCurl/xmlParse.html.gz",
write = getNativeSymbolInfo("R_curl_write_binary_data")$address,
file = buf@ref)
# Convert the internal data structure into an R raw vector
b = as(buf, "raw")
if (getRversion() >= "4")
txt = memDecompress(b, asChar = TRUE)
## or txt = Rcompression::gunzip(b)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.