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

constant modifier function #117

Open
matthewstern opened this issue Mar 2, 2021 · 6 comments
Open

constant modifier function #117

matthewstern opened this issue Mar 2, 2021 · 6 comments
Labels
enhancement New feature or request

Comments

@matthewstern
Copy link
Contributor

matthewstern commented Mar 2, 2021

Timi ran into a problem today in which he needed to modify a value of cmapplot_globals - in his case, he wanted to shrink cmapplot_globals$fsize$S to something smaller than 11, the default. This is difficult/impossible to do from outside the the package, because (contrary to it's name!) cmapplot_globals is not a "global" variable from the user's perspective.

We could use a simple setter function modify_globals(name, value) that modifies a certain constant of cmapplot_globals.

Use cases:

# if name is found in cmapplot_globals, change the value of cmapplot_globals$name and return confirmation message
modify_globals("fsize$S", 8)

#if name is not found, do nothing and return error message
modify_globals("foo", 5)

this should be easy to do with the function assign... something like assign(paste0("cmapplot_globals$", name), value)... although I'm not sure that $ works within functions/strings like that.

@matthewstern matthewstern added the enhancement New feature or request label Mar 2, 2021
@nmpeterson
Copy link
Contributor

I would have thought it could just be done with the double arrow assignment, e.g. cmapplot_globals$fsize$S <<- 8), but I just tested that and get:

Error in cmapplot_globals$fsize$S <<- 8 :
cannot change value of locked binding for 'cmapplot_globals'

@dlcomeaux
Copy link
Collaborator

While I think this could be useful, I think this is one that we would want to talk with comms about - do we want smaller text to be an option? The cases I've had where this would have been nice are on caption sizing on small graphs and on-chart labels where I have several things close together. In both of those cases, though, the solution could instead be to change the graphic, rather than the font size.

@matthewstern
Copy link
Contributor Author

@nmpeterson, can you remind me why we defined cmapplot_globals as a named list rather than an environment? I seem to recall it was an env at first but then you had to change it for some reason. (Based on my research, it seems like this sort of modification, if we decide to do it, is easier with an environment.)

@nmpeterson
Copy link
Contributor

I think it was so we could export it? We made the change in 67e0f5f

@matthewstern
Copy link
Contributor Author

Thanks for tracking it down. Here's the PR: #73.

@matthewstern
Copy link
Contributor Author

It's worth noting that is is partially but not completely in #123 (version 1.2), and in a side experiment from a few months ago I created a framework that I think would address this if we decided to move forward with this. See the creation and use of calc_default_aes() in the defunct branch systemfonts_mess.

Most of the work is done, I'd like to implement it at some point.

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

No branches or pull requests

3 participants