EVOLUTION-MANAGER
Edit File: raw.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Raw Vectors</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for raw {base}"><tr><td>raw {base}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Raw Vectors</h2> <h3>Description</h3> <p>Creates or tests for objects of type <code>"raw"</code>. </p> <h3>Usage</h3> <pre> raw(length = 0) as.raw(x) is.raw(x) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>length</code></td> <td> <p>desired length.</p> </td></tr> <tr valign="top"><td><code>x</code></td> <td> <p>object to be coerced.</p> </td></tr> </table> <h3>Details</h3> <p>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 <a href="Comparison.html">Comparison</a>, using the numerical order of the byte representation) work, as do the logical operators (see <a href="Logic.html">Logic</a>) with a bitwise interpretation. </p> <p>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><a href="rawConversion.html">rawToChar</a></code>. </p> <p>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 <code>[0 ... 255]</code> or are <code>NA</code> are set to <code>0</code> (the <code>nul</code> byte). </p> <p><code>as.raw</code> and <code>is.raw</code> are <a href="Primitive.html">primitive</a> functions. </p> <h3>Value</h3> <p><code>raw</code> creates a raw vector of the specified length. Each element of the vector is equal to <code>0</code>. Raw vectors are used to store fixed-length sequences of bytes. </p> <p><code>as.raw</code> attempts to coerce its argument to be of raw type. The (elementwise) answer will be <code>0</code> unless the coercion succeeds (or if the original value successfully coerces to 0). </p> <p><code>is.raw</code> returns true if and only if <code>typeof(x) == "raw"</code>. </p> <h3>See Also</h3> <p><code><a href="rawConversion.html">charToRaw</a></code>, <code><a href="rawConversion.html">rawShift</a></code>, etc. </p> <p><code><a href="Logic.html">&</a></code> for bitwise operations on raw vectors. </p> <h3>Examples</h3> <pre> xx <- raw(2) xx[1] <- as.raw(40) # NB, not just 40. xx[2] <- 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) </pre> <hr /><div style="text-align: center;">[Package <em>base</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>