\HeaderA{raw}{Raw Vectors}{raw}
\aliasA{as.raw}{raw}{as.raw}
\keyword{classes}{raw}
\begin{Description}\relax
Creates or tests for objects of type \code{"raw"}.
\end{Description}
\begin{Usage}
\begin{verbatim}
raw(length = 0)
as.raw(x)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{length}] desired length.
\item[\code{x}] object to be coerced.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
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 \LinkA{Comparison}{Comparison})
work, as do the logical operators (see \LinkA{Logic}{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
\code{\LinkA{rawToChar}{rawToChar}}.

Coercion to raw treats the input values as representing a small
(decimal) integers, so the input is first coerced to integer, and then
values which are outside the range \code{[0 ... 255]} or are
\code{NA} are set to \code{0} (the \code{nul} byte).
\end{Details}
\begin{Value}
\code{raw} creates a raw vector of the specified length.
Each element of the vector is equal to \code{0}.
Raw vectors are used to store fixed-length sequences of bytes.

\code{as.raw} attempts to coerce its argument to be of raw
type.  The (elementwise) answer will be \code{0} unless the
coercion succeeds.
\end{Value}
\begin{SeeAlso}\relax
\code{\LinkA{charToRaw}{charToRaw}}, \code{\LinkA{rawShift}{rawShift}}, etc.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
xx <- raw(2)
xx[1] <- as.raw(40)     # NB, not just 40.
xx[2] <- charToRaw("A")
xx

x <- "A test string"
(y <- charToRaw(x))
is.vector(y) # TRUE
rawToChar(y)

isASCII <-  function(txt) all(charToRaw(txt) <= as.raw(127))
isASCII(x)  # true
isASCII("\x9c25.63") # false  (in Latin-1, this is an amount in UK pounds)
\end{ExampleCode}
\end{Examples}

