Package 'english'

Title: Translate Integers into English
Description: Allow numbers to be presented in an English language version, one, two, three, ... Ordinals are also available, first, second, third, ... and indefinite article choice, "a" or "an".
Authors: John Fox, Bill Venables, Anthony Damico and Anne Pier Salverda
Maintainer: Bill Venables <[email protected]>
License: GPL-2
Version: 1.2-6
Built: 2025-01-03 07:10:59 UTC
Source: CRAN

Help Index


"_PACKAGE" Numbers in Englis Words

Description

Converts numerical vectors into object that display as English words

Usage

as.english(x, ...)

english(x, ...)

## Default S3 method:
english(x, ...)

## S3 method for class 'numeric'
english(x, UK, ...)

## S3 method for class 'english'
as.numeric(x, ...)

## S3 method for class 'english'
print(x, ...)

## S3 method for class 'english'
rep(x, ...)

## S3 method for class 'english'
x[i]

## S3 method for class 'english'
format(x, ...)

## S3 method for class 'english'
as.character(x, ...)

## S3 method for class 'english'
sort(x, decreasing = FALSE, ...)

Arguments

x

A numerical vector, usually integer.

...

Additional arguments passed on, currently mostly ignored

UK

Logical, Use the UK (English) style (TRUE) or the USA (American) style (FALSE). The default can be set as options(english.UK = TRUE); if unset, a suitable style is guessed from the user's current locale.

i

Index vector of any kind

decreasing

Logical: should the sorting be in decreasing order?

Value

A numerical object that can be printed as English words, or coerced to character as English words

Examples

english(10000) + (-5):5
set.seed(123)
(jumble <- english(sample(1:20)))
sort(jumble)
(x <- english(sample(1:100, 10)))
sort(x)
toupper(english(1:10))
## For mothers of small children:
cat(paste("This is the", ordinal(1:5), "time I've told you!"), sep = "\n")

Add Indefinite Article

Description

Adds an initial indefinite article "a" or "an" to a numerical object expressed either as digits or as words in the result. The capitalized form, Initial, capitalizes the initial letter: "An" or "A".

Usage

indefinite(n, ...)

## S3 method for class 'numeric'
indefinite(n, words = TRUE, ...)

## S3 method for class 'english'
indefinite(n, words = TRUE, ...)

## S3 method for class 'ordinal'
indefinite(n, ...)

## S3 method for class 'character'
indefinite(n, ...)

Indefinite(n, ...)

Arguments

n

either a numeric vector or a ordinal character string.

...

Extra arguments, currently ignored

words

logical: should the numbers be expressed as words (TRUE) or digits (FALSE)?

Value

A character string vector with an article prepended, either capitalized or not.

Examples

indefinite(1:12)
paste0(Indefinite(1:12, FALSE), "-stage process")
cat(paste(Indefinite(ordinal(1:10)), " point is ...\n", sep = ""))

English Arithmetic

Description

Allows arithmetic operations on "english" class objects. To make sense the operation should return an integer value.

Usage

## S3 method for class 'english'
Ops(e1, e2)

Arguments

e1

Numeric vector of object of class "english".

e2

Numeric vector of object of class "english".

Value

Numeric vector of class "english"

Examples

english(1:10)^2 + 1:10
english(100) + (-5):5

Ordinal Numbers

Description

Generates character strings of the ordinal version of numbers in English words.

Usage

ordinal(x, ...)

## S3 method for class 'english'
ordinal(x, ...)

## S3 method for class 'numeric'
ordinal(x, ...)

## S3 method for class 'character'
ordinal(x, ...)

## S3 method for class 'ordinal'
print(x, ...)

Arguments

x

A numeric vector, usually integer, or an object of class "ordinal"

...

Ignored. Included only for compatibility.

Value

A character string vector of ordinal versions of the number, with S3 class "ordinal"

Examples

ordinal(1:12)

Express Numbers in Words

Description

Convert numerical objects to Enghish character strings. A convenience function for use mainly with RMarkdown in-text inserts. The capitalized version, Words, makes the initial letter of the result upper case.

Usage

words(x)

Words(x)

Arguments

x

A numeric vector, usually integer

Value

A character string vector with the numbers expressed in English words.

Examples

cat("The Duke of York had ", words(10006), " men.\n", sep = "")
cat("How many did he have? ", Words(10006), ".\n", sep = "")