readBinFragments

0th

Percentile

Reads binary data from disjoint sections of a connection or a file

Reads binary data from disjoint sections of a connection or a file.

Keywords
IO
Usage
## S3 method for class 'default':
readBinFragments(con, what, idxs=1, size=NA, ..., verbose=FALSE)
Arguments
con
A connection or the pathname of an existing file.
what
A character string or an object specifying the the data type (mode()) to be read.
idxs
A vector of (non-duplicated) indices or a Nx2 matrix of N from-to index intervals specifying the elements to be read.
size
The size of the data type to be read. If NA, the natural size of the data type is used.
...
Additional arguments passed to readBin().
verbose
A logical or a Verbose object.
Value

See Also

writeBinFragments().

Aliases
  • readBinFragments.default
  • readBinFragments
Examples
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Create a data file
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
data <- 1:255
size <- 2
pathname <- tempfile("exampleReadBinFragments")
writeBin(con=pathname, data, size=size)


# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Read and write using index vectors
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Read every 16:th byte in the file
idxs <- seq(from=1, to=255, by=16)
x <- readBinFragments(pathname, what="integer", size=size, signed=FALSE, idxs=idxs)
stopifnot(identical(x, data[idxs]))
print(x)

# Update every 16:th byte in the file
x0 <- x
idxs <- seq(from=1, to=255, by=16)
writeBinFragments(pathname, idxs=idxs, rev(x), size=size)
x <- readBinFragments(pathname, what="integer", size=size, signed=FALSE, idxs=idxs)
print(x)
stopifnot(identical(rev(x0), x))

# Update every 16:th byte in the file
idxs <- seq(from=1, to=255, by=16)
writeBinFragments(pathname, idxs=idxs, rev(x), size=size)
x <- readBinFragments(pathname, what="integer", size=size, signed=FALSE, idxs=idxs)
print(x)
stopifnot(identical(x0, x))

# Read the complete file
x <- readBin(pathname, what="integer", size=size, signed=FALSE, n=length(data))
stopifnot(identical(x, data))


# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Clean up
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
file.remove(pathname)
Documentation reproduced from package R.utils, version 1.3.3, License: LGPL (>= 2.1)

Community examples

Looks like there are no examples yet.