MyNixOS website logo
Description

Convert Letters to Numbers and Back as on a Telephone Keypad.

Convert English letters to numbers or numbers to English letters as on a telephone keypad. When converting letters to numbers, a character vector is returned with "A," "B," or "C" becoming 2, "D," "E", or "F" becoming 3, etc. When converting numbers to letters, a character vector is returned with multiple elements (i.e., "2" becomes a vector of "A," "B," and "C").

phonenumber

R-CMD-check CRAN_Status_Badge CoverageStatus RStudio CRAN mirrordownloads

Background

When I recently posted some of my Turbo Pascal Stuff, I found an incomplete program that was supposed to do this. I was active on BBSes and, though I don’t recall the reason, I wanted a way to determine the possible words spelled by the BBS phone numbers (and/or how to determine what phone numbers correspond to words/phrases). I never got around to finishing the second part (numbers to letters) in Turbo Pascal, though.

I decided to create this functionality in R for three reasons:

  1. to see if I could write the functions
  2. to learn to publish a package to CRAN
  3. to serve as a possible pedagogical example for others as it involves working with lists, splitting strings, and the expand.grid function.

Telephone keypad

For purposes of this package, the mapping of numbers to letters on a telephone’s keypad are as follows:

  • Default behavior - if parameter qz is omitted (or has a value other than 0):
    • 2 corresponds to A, B, C
    • 3 corresponds to D, E, F
    • 4 corresponds to G, H, I
    • 5 corresponds to J, K, L
    • 6 corresponds to M, N, O
    • 7 corresponds to P, Q, R, S
    • 8 corresponds to T, U, V
    • 9 corresponds to W, X, Y, Z
    • 0 and 1 have no corresponding letters
  • Alternate behavior - if parameter qz = 0:
    • 2 corresponds to A, B, C
    • 3 corresponds to D, E, F
    • 4 corresponds to G, H, I
    • 5 corresponds to J, K, L
    • 6 corresponds to M, N, O
    • 7 corresponds to P, R, S
    • 8 corresponds to T, U, V
    • 9 corresponds to W, X, Y
    • 0 corresponds to Q, Z
    • 1 has no corresponding letters

Installation

  • phonenumber is available on CRAN and can be installed accordingly:
install.packages("phonenumber")
library(phonenumber)
  • You can also install phonenumber from GitHub using the devtools package:
install.packages("devtools")
library(devtools)
install_github("scumdogsteev/phonenumber")
library(phonenumber)

Usage

The package consists of two functions:

  1. letterToNumber - converts letters in a string to numbers
  2. numberToLetter - converts numbers in a string to letters

Both functions convert non-alphanumeric characters to dash (-) and perform no conversion on their respective base character type (i.e., letterToNumber leaves letters as is and numberToLetter leaves numbers as is).

Examples

letterToNumber converts a string containing letters into the corresponding numbers on a telephone’s keypad. For example, if the user wants to know what telephone number corresponds to “Texas:”

string <- "Texas"
letterToNumber(string)
#> [1] "83927"

numberToLetter converts a string containing numbers into the corresponding letters on a telephone’s keypad. For example, if the user wants to know what possible character strings could be spelled by a sequence of numbers (e.g., 22):

string <- "22"
numberToLetter(string)
#> [1] "AA" "AB" "AC" "BA" "BB" "BC" "CA" "CB" "CC"
Metadata

Version

0.2.3

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows