to_title_case_pt()
converts a character vector to title case, but
keeping some classes of words in lower case.
In written Portuguese (PT), when converting to title case, it is not usual to keep in title case some words, like prepositions, conjunctions, articles and some kinds of pronouns. This function locates those cases and converts them to lower case.
(Adapted from the original function to_title_case()
by Jose de Jesus
Filho)
Usage
to_title_case_pt(
x,
articles = TRUE,
conjunctions = TRUE,
oblique_pronouns = TRUE,
prepositions = TRUE,
custom_rules = c(`(.)\\bD(el)\\b` = "\\1d\\2")
)
Arguments
- x
A
character
vector.- articles
(Optional) A
logical
flag indicating if articles should be converted (default:TRUE
).- conjunctions
(Optional) A
logical
flag indicating if conjunctions should be converted (default:TRUE
).- oblique_pronouns
(Optional) A
logical
flag indicating if oblique pronouns should be converted (default:TRUE
).- prepositions
(Optional) A
logical
flag indicating if prepositions should be converted (default:TRUE
).- custom_rules
(Optional) A
character
vector with custom rules to be applied. The syntax isc("regex" = "replacement")
. The default isc("(.)\\bD(el)\\b" = "\\1d\\2")
, which converts Del to del.
Value
A character
vector.
See also
Other string functions.:
extract_initials()
Examples
to_title_case_pt("Desterro de Entre Rios")
#> [1] "Desterro de entre Rios"
#> [1] "Desterro de entre Rios" # Expected
to_title_case_pt("Pablo Del Rei")
#> [1] "Pablo del Rei"
#> [1] "Pablo del Rei" # Expected
to_title_case_pt("Sant'ana do Livramento")
#> [1] "Sant'Ana do Livramento"
#> [1] "Sant'Ana do Livramento" # Expected
to_title_case_pt("Alta Floresta d'Oeste")
#> [1] "Alta Floresta D'Oeste"
#> [1] "Alta Floresta D'Oeste" # Expected