Package {verbaliseR}


Title: Make your Text Mighty Fine
Version: 0.2.0
Description: Turn R analysis outputs into full sentences, by writing vectors into in-sentence lists, pluralising words conditionally, spelling out numbers if they are at the start of sentences, writing out dates in full following US or UK style, and managing capitalisations in tidy data.
License: MIT + file LICENSE
Encoding: UTF-8
Language: en-GB
URL: https://github.com/cararthompson/verbaliseR, https://cararthompson.github.io/verbaliseR/
BugReports: https://github.com/cararthompson/verbaliseR/issues
Imports: cli (≥ 3.6.0), rlang (≥ 1.1.0)
Suggests: dplyr, testthat (≥ 3.0.0), withr
Config/testthat/edition: 3
Config/roxygen2/version: 8.0.0
NeedsCompilation: no
Packaged: 2026-12-03 18:17:19 UTC; Cara
Author: Cara Thompson ORCID iD [aut, cre]
Maintainer: Cara Thompson <packages@cararthompson.com>
Repository: CRAN
Date/Publication: 2026-12-04 13:40:02 UTC

verbaliseR: Make your Text Mighty Fine

Description

logo

Turn R analysis outputs into full sentences, by writing vectors into in-sentence lists, pluralising words conditionally, spelling out numbers if they are at the start of sentences, writing out dates in full following US or UK style, and managing capitalisations in tidy data.

Author(s)

Maintainer: Cara Thompson cara.r.thompson@gmail.com (ORCID)

Authors:

See Also

Useful links:


Turn vectors into lists with any specified linking word

Description

Turn vectors into lists with any specified linking word

Usage

listify(items, linking_word = "and", oxford_comma = FALSE)

Arguments

items

A vector of items to turn into a list phrase (e.g. c("a", "b", "c")).

linking_word

Defaults to "and". Can be anything.

oxford_comma

logical. Defaults to FALSE. If TRUE, an oxford comma is added (e.g. "a, b, and c"). This also applies to lists of two items, which is useful when nesting lists (e.g. "a, b or c, and d").

Value

A string in the form of a list (e.g. "a, b and c")

See Also

Other verbaliseR functions: num_to_text(), pluralise(), prettify_date(), restore_capitals()

Examples

listify(c("a", "b", "c"), "or")
listify(c("a", "b", "c"), oxford_comma = TRUE)


Spell out numbers if they are smaller than ten

Description

Spell out numbers if they are smaller than ten

Usage

num_to_text(
  number,
  sentence_start = FALSE,
  zero_or_no = "no",
  uk_or_us = c("UK", "US"),
  big_mark = ","
)

Arguments

number

Whole number(s) as numeric or integer, to be turned into text. Numbers 0-10 (as well as 100 and 1000) are always written out in full, regardless of their place in the sentence. Numbers 11-1000 are written out in full if they are at the beginning of a sentence. Numbers greater than 1000 are returned as numerals, formatted with big_mark. Negative numbers follow the same rules, with "minus" in front (e.g. "minus three"). Numbers with decimals are always returned as numerals. Can be a vector (e.g. a column in dplyr::mutate()), in which case each number is turned into text; missing values stay missing.

sentence_start

Logical. If TRUE, numbers up to 1000 are written out in full, and their first letter is capitalised.

zero_or_no

Specify what to print when the number is 0. Defaults to "no". Can be any string.

uk_or_us

Defaults to UK which adds an "and" between "hundred" and other numbers (e.g. "One hundred and five"). If "US" is chosen, the "and" is removed (e.g. "One hundred five").

big_mark

Defaults to "," (e.g. "1,999").

Value

A character vector the same length as number

See Also

Other verbaliseR functions: listify(), pluralise(), prettify_date(), restore_capitals()

Examples

num_to_text(3)
num_to_text(333, sentence_start = TRUE)
num_to_text(-3)
num_to_text(c(0, 5, 50, 5000))


Pluralise words if their accompanying number is not 1

Description

Pluralise words if their accompanying number is not 1

Usage

pluralise(
  word,
  count,
  plural = "s",
  add_or_swap = c("add", "swap"),
  include_number = TRUE,
  sentence_start = FALSE,
  zero_or_no = "no",
  uk_or_us = c("UK", "US"),
  big_mark = ","
)

Arguments

word

A word which should be returned as plural if count is not equal to 1.

count

A number to apply to word. Can be a vector (e.g. a column in dplyr::mutate()), in which case word and plural can either be single words or vectors of the same length as count. Missing counts return missing values.

plural

How to make the plural; defaults to an "s" which is added at the end of the word. Can be anything. See add_or_swap.

add_or_swap

Choose between add (add the plural form (e.g. "s") onto the end; e.g. house becomes houses) and swap (swap for the plural form; e.g. mouse becomes mice)

include_number

Logical. If TRUE, the number will be turned into text, as per num_to_text(), using zero_or_no, uk_or_us and big_mark.

sentence_start

Logical. Defaults to FALSE, which results in only numbers 0-10 being written out in full. If TRUE, numbers 11-1000 are written out in full if included. (If include_number is FALSE, the first letter of word is capitalised, and the rest of the word is left as is.)

zero_or_no

Specify what to print when the number is 0. Defaults to "no". Can be any string.

uk_or_us

Defaults to UK which adds an "and" between "hundred" and other numbers (e.g. "One hundred and five"). If "US" is chosen, the "and" is removed (e.g. "One hundred five").

big_mark

Defaults to "," (e.g. "1,999").

Value

A word which is pluralised or not based on the value of count, or a character vector the same length as the longest of word, count and plural

See Also

Other verbaliseR functions: listify(), num_to_text(), prettify_date(), restore_capitals()

Examples

pluralise("penguin", 3)
pluralise("bateau", 1234, "x")
pluralise("sheep", 333, "sheep", add_or_swap = "swap", sentence_start = TRUE)
pluralise(c("penguin", "seal"), c(1, 3))


Render ordinal dates in UK or US style

Description

Render ordinal dates in UK or US style

Usage

prettify_date(
  date_to_format = Sys.Date(),
  uk_or_us = c("UK", "US"),
  formal_or_informal = c("informal", "formal")
)

Arguments

date_to_format

The date to use. It must be either be of class Date or a string written as "YYYY-MM-DD" or "YYYY/MM/DD". Can be a vector (e.g. a column in dplyr::mutate()); missing dates stay missing.

uk_or_us

Defaults to "UK", which results in outputs like "12th September 2022"; if "US", the output resembles "September 12th, 2022".

formal_or_informal

Defaults to "informal", so the ordinals are included (e.g. "st", "nd", "rd", "th"). If "formal" is chosen, the ordinals are omitted (e.g. "12 September 2022").

Value

A string (e.g. "12th September 2022"), or a character vector the same length as date_to_format

See Also

Other verbaliseR functions: listify(), num_to_text(), pluralise(), restore_capitals()

Examples

prettify_date(Sys.Date(), "UK", "informal")
prettify_date(c("2022-09-01", "2022-09-02"), "US", "formal")

Restore custom capitalisation in a string

Description

Restore custom capitalisation in a string

Usage

restore_capitals(x, items_to_capitalise)

Arguments

x

A string (or vector of strings) in which capitalisation needs to be restored

items_to_capitalise

Whole words or acronyms in which capitalisation must be retained; special characters can be included (e.g. "R2-D2"). Matching ignores case, so items are restored whether their capitalisation has been lost completely (e.g. "ebook") or partially (e.g. "Ebook").

Value

A string (or vector of strings) with restored capitals

See Also

Other verbaliseR functions: listify(), num_to_text(), pluralise(), prettify_date()

Examples

x <- "Should i tell c-3po the french call him z-6po?"
restore_capitals(x, c("I", "C-3PO", "French", "Z-6PO"))