raw(length = 0L) as.raw(x) is.raw(x)
length | an integer indicating the length of the vector to create. |
x | an object. |
raw() | returns a vector of mode "raw" and length of length. |
as.raw() | returns a raw object if the original object x can be converted to a raw object. If it cannot be converted, an warning is displayed. |
is.raw() | returns a logical value to indicate whether the object x is a raw object. |
raw(2) # [1] 00 00as.raw(c(-1,0,10,255,256)) #Warning: out-of-range values treated as 0 in coercion to raw # [1] 00 00 0a ff 00
x <- runif(10) is.raw(x) # [1] FALSE
# serialize an object into a vector of raw bytes r <- serialize(x, NULL)
is.raw(r) # [1] TRUE
# Re-create the object from the raw vector y <- unserialize(r) identical(x, y) # [1] TRUE
# Convert a character string to raw bytes charToRaw('hello') # [1] 68 65 6c 6c 6f