raw                   package:base                   R Documentation

_R_a_w _V_e_c_t_o_r_s

_D_e_s_c_r_i_p_t_i_o_n:

     Creates or tests for objects of type '"raw"'.

_U_s_a_g_e:

     raw(length = 0)
     as.raw(x)
     is.raw(x)

_A_r_g_u_m_e_n_t_s:

  length: desired length.

       x: object to be coerced.

_D_e_t_a_i_l_s:

     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) 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
     '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 '[0 ... 255]' or are 'NA'
     are set to '0' (the 'nul' byte).

_V_a_l_u_e:

     'raw' creates a raw vector of the specified length. Each element
     of the vector is equal to '0'. 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.

     'is.raw' returns true if and only if 'typeof(x) == "raw"'.

_S_e_e _A_l_s_o:

     'charToRaw', 'rawShift', etc.

_E_x_a_m_p_l_e_s:

     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)
     is.raw(x)
     is.raw(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)

