scales
scales copied to clipboard
Split long strings without spaces
Currently, label_wrap() only splits a string if there are spaces, however, there is no way (as far as I can tell) to force wrapping even if there is no space to ensure we do not overflow the specified width.
Example:
label_wrap(10)("Incomprehensibility")
should produce "Incomprehe\nnsibility".
Other interesting variants could be:
label_wrap(10, camel_case=TRUE)("defaultOptionA")
which splits (if needed) at "(?<=[[:lower:]])(?=[[:upper:]])" thus, "default\nOptionA".
and specify allowed split characters:
label_wrap(10, split="[[:space:]_]")("default_option_a")
will produce "default\noption_a".
Note that all the above can work together in a well-defined way:
label_wrap(10, force=TRUE, split="[[:space:]_]", camel_case=TRUE)("defaultOptionA_allowed_wheneverpossible")
would produce "default\nOptionA\nallowed\nwheneverpo\nssible"
This is outside the scope of scales as word wrapping is it's own horrible beast safe for very simple cases such as what scales provide. ggtext/gridtext offers a much richer word-wrapping featureset