rawConversion              package:base              R Documentation

_C_o_n_v_e_r_t _t_o _o_r _f_r_o_m _R_a_w _V_e_c_t_o_r_s

_D_e_s_c_r_i_p_t_i_o_n:

     Conversion and manipulation of  objects of type '"raw"'.

_U_s_a_g_e:

     charToRaw(x)
     rawToChar(x, multiple = FALSE)

     rawShift(x, n)

     rawToBits(x)
     intToBits(x)
     packBits(x, type = c("raw", "integer"))

_A_r_g_u_m_e_n_t_s:

       x: object to be converted or shifted.

multiple: logical: should the conversion be to a single character
          string or multiple individual characters?

       n: the number of bits to shift.  Positive numbers shift right
          and negative numbers shift left: allowed values are '-8 ...
          8'.

    type: the result type.

_D_e_t_a_i_l_s:

     'packBits' accepts raw, integer or logical inputs, the last two
     without any NAs.

     Note that 'bytes' are not necessarily the same as characters, e.g.
     in UTF-8 domains.

_V_a_l_u_e:

     'charToRaw' converts a length-one character string to raw bytes.

     'rawToChar' converts raw bytes either to a single character string
     or a character vector of single bytes.  (Note that a single
     character string could contain embedded nuls.)

     'rawToBits' returns a raw vector of 8 times the length of a raw
     vector with entries 0 or 1.  'intToBits' returns a raw vector of
     32 times the length of an integer vector with entries 0 or 1. In
     both cases the unpacking is least-significant bit first.

     'packbits' packs its input (using only the lowest bit for raw or
     integer vectors) least-significant bit first to a raw or integer
     vector.

_E_x_a_m_p_l_e_s:

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

     rawToChar(y)
     rawToChar(y, multiple = TRUE)
     (xx <- c(y, as.raw(0), charToRaw("more")))
     rawToChar(xx)
     xxx <- xx
     xxx[length(y)+1] <- charToRaw("&")
     xxx
     rawToChar(xxx)

     rawShift(y, 1)
     rawShift(y, -2)

     rawToBits(y)

