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

Label composer #465

Merged
merged 7 commits into from
Oct 22, 2024
Merged

Label composer #465

merged 7 commits into from
Oct 22, 2024

Conversation

teunbrand
Copy link
Contributor

This PR aim to fix #462.

Briefly, it adds compose_label() that you can use to chain together function to format your labels. This saves one the hassle of writing an anonymous function to inject in-between steps.

@davidhodge931 this is a way to solve #443 too :)

devtools::load_all("~/packages/scales/")
#> ℹ Loading scales
demo_continuous(c(-100, 100), labels = compose_label(abs, label_number()))
#> scale_x_continuous(labels = compose_label(abs, label_number()))

Created on 2024-10-08 with reprex v2.1.1

orig <- x
for (labeller in label_list) {
x <- labeller(x)
attr(x, "orig") <- orig
Copy link
Contributor Author

@teunbrand teunbrand Oct 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attaching the original breaks as an attribute here so that 'aware' functions could use original numeric breaks if they've already been converted to character (when you need a number's sign or something)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe something more specific than orig? orig_label is at least more descriptive

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer orig_breaks then because we attach breaks and not labels as attributes. This confusion just go to show how orig was ambiguous 😅

Merge branch 'main' into compose_labels

# Conflicts:
#	_pkgdown.yml
@thomasp85 thomasp85 merged commit 0f3929a into r-lib:main Oct 22, 2024
12 checks passed
@thomasp85
Copy link
Member

Thank you

@teunbrand teunbrand deleted the compose_labels branch October 22, 2024 08:17
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.

Feature request: composable labelling functions
2 participants