Skip to content

Commit

Permalink
Merge scale calls
Browse files Browse the repository at this point in the history
  • Loading branch information
teunbrand committed Sep 28, 2023
1 parent a7b43b3 commit 900a61a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
12 changes: 10 additions & 2 deletions R/scale-.R
Original file line number Diff line number Diff line change
Expand Up @@ -572,17 +572,25 @@ Scale <- ggproto("Scale", NULL,
return()
},

update_params = function(self, params, default = FALSE) {
update_params = function(self, params, default = FALSE, call = NULL) {

fields <- intersect(self$fields, names(params))
extra <- setdiff(names(params), fields)

if (length(extra) > 0) {
cli::cli_warn(
"Ignoring unknown scale parameter{?s}: {.and {.field {extra}}}."
"Ignoring unknown scale parameter{?s}: {.and {.field {extra}}}.",
call = call
)
}

if (is.null(self$call)) {
self$call <- call
} else if (!is.null(call)) {
self$call <- call("+", self$call, call)
}
call <- self$call

if (!default) {
# Don't update fields that were already defined in non-default scale
fields <- setdiff(fields, call_args_names(self$call))
Expand Down
6 changes: 6 additions & 0 deletions R/scale-partial.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ ScalePartial <- ggproto(

update_params = function(self, params, default = FALSE, call = self$call) {
self$params <- defaults(params, self$params)
if (is.null(self$call)) {
self$call <- call
} else if (!is.null(call)) {
self$call <- call("+", self$call, call)
}
return()
},

clone = function(self) {
Expand Down

0 comments on commit 900a61a

Please sign in to comment.