Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically determine prefix and suffix from tags #172

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

thomas-neitmann
Copy link

I have implemented an automatic detection of the tag_prefix and tag_suffix from the tag_levels as described in #169. It works like this:

  1. Look whether tag_levels contains one of the supported tags using grepl()
  2. If it does and tag_levels is longer than 1 character then find the index of the supported tag inside tag_levels
  3. Use anything that comes before this index as tag_prefix
  4. Use anything that comes after this index as tag_suffix

Some examples:

  • In the case of tag_levels = "A", tag_prefix and tag_suffix are left blank.
  • In case of tag_levels = "[A", tag_prefix is set to "]" and tag_suffix is left blank.
  • In case of tag_levels = "A}", tag_prefix is left blank and tag_suffix is set to "}".
  • In case of tag_levels = "(A)", tag_prefix is is set to "(" and tag_suffix is set to ")".

Importantly, in the current implentation the automatic detection of the prefix is not "activated" when tag_prefix is set. The same is true for the suffix is tag_suffix is set.

library(ggplot2)
p1 <- ggplot(mtcars, aes(mpg, hp)) + geom_point()
p2 <- ggplot(mtcars, aes(wt)) + geom_histogram()

p1 + p2 + plot_annotation(tag_levels = "1")

image

p1 + p2 + plot_annotation(tag_levels = "A)")

image

p1 + p2 + plot_annotation(tag_levels = "[I]")

image

p1 + p2 + plot_annotation(tag_levels = "{a")

image

p1 + p2 + plot_annotation(tag_levels = "(A)", tag_prefix = "[", tag_suffix = "]")

image

@thomasp85
Copy link
Owner

On second thought, I think the best approach is something incorporating glue. Your current checks for which formats to use will fail if prefix or suffix contains any of the recognised tokens

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants