parts are lines from a paragraph pasted out of a PDF or Word document, where the source's own line wrapping – not paragraph structure – put a break between them. Lines are joined with a space, except where a line ends in a hyphen attached to a word: there the break is joined without a space, and the hyphen is kept ("oven-" / "dried" becomes "oven-dried").

util_dewrap_join(parts, dehyphenate = FALSE)

Arguments

parts

character vector of trimmed lines to join, in order

dehyphenate

remove the hyphen at a lowercase-to-lowercase break?

Value

a list: text, the joined string, and hyphen_joins, the word formed at each break that ended in a hyphen

Details

A hyphen at a break cannot be told apart from the source's own: a word split mid-word ("collec-" / "tion") and a genuine compound ("erosion-" / "resistant") look the same. Keeping the hyphen never deletes a character; with dehyphenate = TRUE it is removed instead where a lowercase letter precedes it and the next line resumes in lowercase, giving "collection" but also "erosionresistant". Either way, every join at a hyphen is returned in hyphen_joins so it can be checked. A line ending in a hyphen before "and" or "or" ("pre-" / "and post-fire") is a suspended hyphen and keeps its space, as does a line ending in +/-.