Title: | Make your Text Mighty Fine |
---|---|
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. |
Authors: | Cara Thompson [aut, cre] |
Maintainer: | Cara Thompson <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1 |
Built: | 2024-11-22 03:05:01 UTC |
Source: | https://github.com/cararthompson/verbaliser |
Turn vectors into lists with any specified linking word
listify(items, linking_word = "and", oxford_comma = FALSE)
listify(items, linking_word = "and", oxford_comma = FALSE)
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 |
|
A string in the form of a list (e.g. "a, b and c")
listify(c("a", "b", "c"), "or")
listify(c("a", "b", "c"), "or")
Spell out numbers if they are smaller than ten
num_to_text( number, sentence_start = FALSE, zero_or_no = "no", uk_or_us = "UK", big_mark = "," )
num_to_text( number, sentence_start = FALSE, zero_or_no = "no", uk_or_us = "UK", big_mark = "," )
number |
Whole number as |
sentence_start |
Logical. If |
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"). |
A string
num_to_text(3) num_to_text(333, sentence_start = TRUE)
num_to_text(3) num_to_text(333, sentence_start = TRUE)
Pluralise words if their accompanying number is not 1
pluralise( word, count, plural = "s", add_or_swap = "add", include_number = TRUE, sentence_start = FALSE, zero_or_no = "no", uk_or_us = "UK", big_mark = "," )
pluralise( word, count, plural = "s", add_or_swap = "add", include_number = TRUE, sentence_start = FALSE, zero_or_no = "no", uk_or_us = "UK", big_mark = "," )
word |
A word which should be returned as plural if |
count |
A number to apply to |
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 |
Choose between |
include_number |
Logical. If |
sentence_start |
Logical. Defaults to |
zero_or_no |
Prefered string to use where count == 0. Defaults to "no". Can be anything. |
uk_or_us |
Only used if |
big_mark |
Passed to |
A word which is pluralised or not based on the value of count
pluralise("penguin", 3) pluralise("bateau", 1234, "x") pluralise("sheep", 333, "sheep", add_or_swap = TRUE, sentence_start = TRUE)
pluralise("penguin", 3) pluralise("bateau", 1234, "x") pluralise("sheep", 333, "sheep", add_or_swap = TRUE, sentence_start = TRUE)
Render ordinal dates in UK or US style
prettify_date( date_to_format = Sys.Date(), uk_or_us = "UK", formal_or_informal = "informal" )
prettify_date( date_to_format = Sys.Date(), uk_or_us = "UK", formal_or_informal = "informal" )
date_to_format |
The date to use. It must be either be of class |
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"). |
A string (e.g. "12th September 2022")
prettify_date(Sys.Date(), "UK", "informal")
prettify_date(Sys.Date(), "UK", "informal")
Restore sustom capitalisation in a string
restore_capitals(x, items_to_capitalise)
restore_capitals(x, items_to_capitalise)
x |
A string 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") |
A string with restored capitals
x <- "Should i tell c-3po the french call him z-6po?" restore_capitals(x, c("I", "C-3PO", "French", "Z-6PO"))
x <- "Should i tell c-3po the french call him z-6po?" restore_capitals(x, c("I", "C-3PO", "French", "Z-6PO"))