aphalo / ggpmisc

R package ggpmisc is an extension to ggplot2 and the Grammar of Graphics
https://docs.r4photobiology.info/ggpmisc
97 stars 6 forks source link

Implement format templates for label assembly in use_label() #21

Open aphalo opened 2 years ago

aphalo commented 2 years ago

I just implemented function use_label() that uses paste() to assemble the combined label and supports a single value for sep. This is a simple user interface usable in many cases. A function fmt_label()could be also useful when users want to have arbitrary separators or additional text. This is to keep a note that if use_label() turns out to be limiting, a function using a template for the overall format would be a reasonable UI, although not necessarily very easy to implement, in particular handling of parsing errors.

aphalo commented 1 year ago

Two possible approaches: 1) create a wrapper on sprintf() that understands the short names of the labels and maps the assembled character vector to the label aesthetic; 2) enhance use_label() to have an interface similar to R's paste(). This does not seem urgent, so I will keep it on hold for some time.

aphalo commented 4 months ago

I could attempt in the future to implement 2), that is accepting both label names and ordinary character strings. The current implementation seems like an inelegant kludge even if it gets the job done. For the time being, accepting individual character strings through an ellipsis parameter in addition to a character vector through parameter labels is an improvement.