Learn R Programming

sfsmisc (version 0.9-4)

AsciiToInt: Character to and from Integer Codes Conversion

Description

AsciiToInt returns integer codes in 0:255 for each (one byte) character in strings. ichar is an alias for it, for old S compatibility.

strcodes implements in Rthe basic engine for translating characters to corresponding integer codes.

chars8bit() is the inverse function of AsciiToint, producing (one byte) characters from integer codes.

Usage

AsciiToInt(strings)
     ichar(strings)
chars8bit(i = 0:255)
strcodes(x, table = chars8bit(0:255))

Arguments

strings, x
character vector.
i
numeric (integer) vector of values in 0:255.
table
a vector of (unique) character strings, typically of one character each.

Value

  • AsciiToInt (and hence ichar) and chars8bit return a vector of the same length as their argument.

    strcodes(x, tab) returns a list of the same length and names as x with list components of integer vectors with codes in 0:255.

Details

Only codes in 0:127 make up the ASCII encoding which should be identical for all Rversions, whereas the upper half is often determined from the ISO-8859-1 (aka ISO-Latin 1) encoding, but may well differ, depending on the locale setting, see also Sys.setlocale.

Examples

Run this code
chars8bit(65:70)#-> "A" "B" .. "F"
stopifnot(identical(LETTERS,   chars8bit(65:90)),
          identical(AsciiToInt(LETTERS), 65:90))

strcodes(c(a= "ABC", ch="1234", place = "Z�rich"))
## gives
$a
[1] 65 66 67

$ch
[1] 49 50 51 52

$place
[1]  90 252 114 105  99 104

Run the code above in your browser using DataLab