Light Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

POC: Alternative way of determining parameters#6101

Draft
teunbrand wants to merge 7 commits intotidyverse:mainfrom
teunbrand:alt_params
Draft

POC: Alternative way of determining parameters#6101
teunbrand wants to merge 7 commits intotidyverse:mainfrom
teunbrand:alt_params

Conversation

Copy link
Collaborator

teunbrand commented Sep 12, 2024 *
edited
Loading

This PR explores to fix #1516.

It follows the approach proposed in #1516 (comment).
I've numbered the comments in the code below so it'd be easier to follow.

This PR is currently only implemented for 1 stat and 2 geoms, complying with 'a minimal version' of the approach.
It is for this reason still a POC, and we still have to decide if we like this approach.

teunbrand commented Sep 12, 2024
Comment on lines +66 to +67
default_params = NULL,

Copy link
Collaborator Author

teunbrand Sep 12, 2024 *
edited
Loading

Choose a reason for hiding this comment

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

  1. The Geom and Stat classes have a new field that can hold a named list of default parameters.

teunbrand commented Sep 12, 2024
Comment on lines +214 to +216
if (!is.null(self$default_params)) {
return(names(self$default_params))
}
Copy link
Collaborator Author

teunbrand Sep 12, 2024

Choose a reason for hiding this comment

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

  1. We simply return the name of the default parameter list for checking layer() input. For backward compatibility, if this list isn't present, we resort to the old way of determining input.

teunbrand commented Sep 12, 2024
Comment on lines +433 to +434
params <- defaults(c(self$geom_params, self$aes_params), self$geom$default_params)
self$computed_geom_params <- self$geom$setup_params(data, params)
Copy link
Collaborator Author

teunbrand Sep 12, 2024

Choose a reason for hiding this comment

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

  1. Before we add computed components to the parameters, we initialise the parameters from the new field

teunbrand commented Sep 12, 2024

# Trim off extra parameters
params <- params[intersect(names(params), self$parameters())]
params <- filter_args(params, self$draw_panel)
Copy link
Collaborator Author

teunbrand Sep 12, 2024 *
edited
Loading

Choose a reason for hiding this comment

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

  1. We then filter the parameters on the go in the compute/draw_layer() and compute/draw_panel() methods. Implementation of filter_args() in the utils file.

teunbrand commented Sep 12, 2024
Comment on lines +76 to +77
default_params = NULL,

Copy link
Collaborator Author

teunbrand Sep 12, 2024

Choose a reason for hiding this comment

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

  1. We take the same approach with Stats

teunbrand commented Sep 12, 2024
Comment on lines +184 to +188
default_params = list(
na.rm = FALSE, orientation = NA,
fun.data = NULL, fun = NULL, fun.max = NULL, fun.min = NULL,
fun.args = list()
),
Copy link
Collaborator Author

teunbrand Sep 12, 2024

Choose a reason for hiding this comment

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

  1. As an example stat, here is how we could implement the default parameters for StatSummary

teunbrand commented Sep 12, 2024
Comment on lines +181 to +187
default_params = list(
na.rm = FALSE, width = NULL, orientation = NA, outliers = TRUE,
lineend = "butt", linejoin = "mitre", fatten = 2, outlier.colour = NULL,
outlier.fill = NULL, outlier.shape = NULL, outlier.size = NULL,
outlier.stroke = 0.5, outlier.alpha = NULL, notch = FALSE, notchwidth = 0.5,
staplewidth = 0, varwidth = FALSE, flipped_aes = FALSE
),
Copy link
Collaborator Author

teunbrand Sep 12, 2024

Choose a reason for hiding this comment

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

  1. As a geom example, here is how we could implement the default parameter list for GeomBoxplot

teunbrand commented Sep 12, 2024

ggname("geom_violin", grobTree(
GeomPolygon$draw_panel(newdata, ...),
inject(GeomPolygon$draw_panel(newdata, !!!params)),
Copy link
Collaborator Author

teunbrand Sep 12, 2024 *
edited
Loading

Choose a reason for hiding this comment

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

  1. Here is a downside of the method: we cannot simply pass dots here as GeomViolin recieves more parameters than GeomPolygon needs. This was the only Geom where this was a problem though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Better way of handling parameters

1 participant