english (version 1.1-3)

as.english: Generic functions and methods for S3 class english

Description

The functions as.english and english are fully equivalent generic constructor functions for the S3 class english, which allows numeric objects to be represented in the form of their customary English expression.

Usage

as.english(x, …)
english(x, …)
# S3 method for default
english(x, …)
# S3 method for numeric
english(x, UK, …)
# S3 method for english
english(x, UK, …)
# S3 method for english
[(x, i)
# S3 method for english
rep(x, …)
# S3 method for english
format(x, …)

Arguments

x

Any numeric object. If the components are not integers, they are rounded. In the case of english.default this may be an object of any class, but will always result in an error.

UK

A logical flag, should English-style numbers be given (TRUE) or American style (FALSE)? If missing, a default value is chosen as TRUE unless the locale in use is guessed to be an English locale of the USA.

For rep, and format arguments passed on to other methods. Ignored in all other cases.

i

Any allowable form of index vector.

Value

An object of class english, if possible, or an error message if not.

Details

The function english is a generic constructor function for objects of class english. The methods either mark the object as having the appropriate class, or, in the case of english.default, result in an error message. The function as.english is provided as a corresponding function to as.roman in the utils package. The method english.english simply allows the constructor function to act as a coercion and to have no effect on objects already of the class.

References

See original note by John Fox in the Programmers Niche section of https://cran.r-project.org/doc/Rnews/Rnews_2005-1.pdf.

See Also

as.character.english, print.english.

Examples

Run this code
# NOT RUN {
english(1010, UK = FALSE)
english(1010, UK = TRUE)
## The default UK setting will depend on the locale:
cat("\n", ifelse(grepl("^(en_us|english_united)",
    tolower(Sys.getlocale("LC_CTYPE"))), "USA", "UK"),
    "English is your default\n")
english(101)       ## UK not given: deduced from locale
as.english(10001001) + (-5):5
# }

Run the code above in your browser using DataCamp Workspace