metrumresearchgroup / yspec

Data Specification for Pharmacometrics
https://metrumresearchgroup.github.io/yspec
5 stars 2 forks source link

Titlecase: some first words don't get capitalized #132

Closed toddyoder closed 2 years ago

toddyoder commented 2 years ago

A short word that would not normally be capitalized in titlecase should be capitalized if it appears at the beginning of a sentence. This example doesn't get handled correctly by yspec.

FOO:
  short: any first word should be capitalized
spec <- yspec::ys_load(here::here("capitalize-me.yml"))
yspec::ys_get_short(spec, title_case = TRUE)
#> $FOO
#> [1] "any First Word Should be Capitalized"
kylebaron commented 2 years ago

Thanks for the report, @toddyoder . yspec relies on tools::toTitleCase for this conversion and it looks like that's how it is handling your example. A workaround would be to specify what you want in the spec, either in the base position or in a namespace

FOO: 
  short: any first word should be capitalized
  short.cap: Any First Word Should be Capitalized
> tools::toTitleCase("any first word should be capitalized")
[1] "any First Word Should be Capitalized"
toddyoder commented 2 years ago

Thanks @kylebaron for the explanation and workaround. Very helpful.