Is the string an honorific?

Share:

Description

Checks that the input contains honorifics (a.k.a. titles or salutations).

Usage

1
2
3
4
5
6
7
assert_all_are_honorifics(x, na_ignore = FALSE,
  severity = getOption("assertive.severity", "stop"))

assert_any_are_honorifics(x, na_ignore = FALSE,
  severity = getOption("assertive.severity", "stop"))

is_honorific(x)

Arguments

x

Input to check.

na_ignore

A logical value. If FALSE, NA values cause an error; otherwise they do not. Like na.rm in many stats package functions, except that the position of the failing values does not change.

severity

How severe should the consequences of the assertion be? Either "stop", "warning", "message", or "none".

Value

is_honorific returns TRUE if the input string contains a valid UK postcode. The assert_* function returns nothing but throws an error when the is_* function returns FALSE.

Note

Single full stops (periods) following a word boundary and preceding a space or the end of the string are stripped. Case is ignored. There is no formal list of official salutations, so this should only be used as a guide, rather than giving a definitive result. Especially note that cultural conventions differ across the world and this function has a UK bias.

References

Many possibilities borrowed from the Salutation dropdown on the MathWorks account creation page. https://www.mathworks.com/accesslogin/createProfile.do

Examples

1
2
x <- c("Mr", "MR", "mr.", "Mister", "masTer", "Mr!", "M.r", ".Mr")
is_honorific(x)