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

Dynamic code generation #345

Closed
Yuri05 opened this issue Jul 22, 2022 · 2 comments
Closed

Dynamic code generation #345

Yuri05 opened this issue Jul 22, 2022 · 2 comments

Comments

@Yuri05
Copy link
Member

Yuri05 commented Jul 22, 2022

Sorry for the delay.
The variable fillLength is created during the call of .parseUpdateAestheticProperty when input argument is "fill"
To prevent potential copy/paste issues of very similar lines of code, most of the functions from aaa-utilities.R directly output R code as character strings (which are then transformed into expressions to be evaluated as actual R code using parse(text) and eval(expression).

Below shows the expression returned when the function .parseUpdateAestheticProperty is called with the arguments "fill" and ribbons.

> .parseUpdateAestheticProperty("fill", "ribbons")

expression(
fillVariable <- gsub("`", "", mapLabels$fill),
fillLength <- length(unique(mapData[, fillVariable])),
suppressMessages(
plotObject <- plotObject + ggplot2::scale_fill_manual(
values = .getAestheticValues(n = fillLength, selectionKey = plotConfiguration$ribbons$fill, aesthetic = "fill")
)
), 
if (isIncluded(fillVariable, "legendLabels")) {
plotObject <- plotObject + ggplot2::guides(fill = "none")
}
)

When the expression is wrapped by eval(), this code is evaluated and

  • Creates the variable fillVariable, column name in the data linked to the fill property
  • Creates the variable fillLength, number of unique values for the fill property (used for selecting the right number of colors)
  • Update the fill properties of the plot plotObject
  • Remove the legend if no mapping was actually defined

Note that changing "fill" by any other property name such as "color" or "alpha" would directly create an evaluated R code with all the property names changed to "color" or "alpha"

Originally posted by @pchelle in #338 (comment)

@Yuri05 Yuri05 closed this as completed Jul 22, 2022
@IndrajeetPatil
Copy link
Member

Did you mean to close this?

I don't see what the issue was.

@Yuri05
Copy link
Member Author

Yuri05 commented Jul 22, 2022

The issue is here: #346

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

No branches or pull requests

2 participants