Creates or tests for objects of type
raw(length = 0) as.raw(x) is.raw(x)
object to be coerced.
The raw type is intended to hold raw bytes. It is possible to extract subsequences of bytes, and to replace elements (but only by elements of a raw vector). The relational operators (see Comparison, using the numerical order of the byte representation) work, as do the logical operators (see Logic) with a bitwise interpretation.
A raw vector is printed with each byte separately represented as a
pair of hex digits. If you want to see a character representation
(with escape sequences for non-printing characters) use
Coercion to raw treats the input values as representing small
(decimal) integers, so the input is first coerced to integer, and then
values which are outside the range
[0 ... 255] or are
NA are set to
is.raw are primitive functions.
raw creates a raw vector of the specified length.
Each element of the vector is equal to
Raw vectors are used to store fixed-length sequences of bytes.
as.raw attempts to coerce its argument to be of raw
type. The (elementwise) answer will be
0 unless the
coercion succeeds (or if the original value successfully coerces to 0).
is.raw returns true if and only if
typeof(x) == "raw".
& for bitwise operations on raw vectors.
xx <- raw(2) xx <- as.raw(40) # NB, not just 40. xx <- charToRaw("A") xx ## 28 41 -- raw prints hexadecimals dput(xx) ## as.raw(c(0x28, 0x41)) as.integer(xx) ## 40 65 x <- "A test string" (y <- charToRaw(x)) is.vector(y) # TRUE rawToChar(y) is.raw(x) is.raw(y) stopifnot( charToRaw("\xa3") == as.raw(0xa3) ) isASCII <- function(txt) all(charToRaw(txt) <= as.raw(127)) isASCII(x) # true isASCII("\xa325.63") # false (in Latin-1, this is an amount in UK pounds)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.