readRaw: Read the Raw Binary Content of a File

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/viewRaw.R

Description

Read the contents of a file as bytes and create an object containing the raw data, plus optionally an interpretation of the bytes as numeric values, plus parameters controlling how to display the data.

Usage

1
2
3
4
readRaw(file, width = NULL, offset = 0, nbytes = NULL,
        machine = "hex", human = "char",
        size = switch(human, char = 1, int = 4, real = 8),
        endian = .Platform$endian, signed = TRUE)

Arguments

file

The name of a file or a connection.

width

The number of bytes to print per row when displaying the data.

offset

An offset within the file to start reading.

nbytes

The number of bytes to read from the file. NULL means read the whole file.

machine

How to print each byte when displaying; either "hex" or "binary".

human

How to print a human-readable form of the data; either "char" (an ASCII character), "int" (an integer), or "real" (a floating point number).

size

The number of bytes used to generate each value when interpreting the raw binary as character or numeric data.

endian

The endianness of the binary data; used when interpreting bytes as numeric values.

signed

Whether the bytes should be interpreted as a signed numeric value.

Details

Each individual byte is printed in the appropriate machine format, but there is only one value printed in the appropriate human format for every size bytes. Consequently, the width must be a multiple of the size.

Value

An object of class "rawBlock".

Author(s)

Paul Murrell

See Also

viewRaw readBin as.character.rawBlock print.rawBlock blockValue readFormat

Examples

1
2
3
4
5
6
7
readLines(hexViewFile("rawTest.txt"))

fileBlock <- readRaw(hexViewFile("rawTest.txt"), width=8)
blockValue(fileBlock)

fileBlock <- readRaw(hexViewFile("rawTest.int"), human="int")
blockValue(fileBlock)

Example output

[1] "test pattern"
 [1] "t" "e" "s" "t" " " "p" "a" "t" "t" "e" "r" "n" "."
 [1]  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] 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

hexView documentation built on May 2, 2019, 7:02 a.m.