Skip to content

Commit c700dc8

Browse files
authored
Protection for position scale's call parameter (#5605)
* protect against exotic calls * misplaced parenthesis * circumvent try_fetch
1 parent 49d7a8d commit c700dc8

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

R/scale-continuous.R

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ scale_x_continuous <- function(name = waiver(), breaks = waiver(),
8686
guide = waiver(), position = "bottom",
8787
sec.axis = waiver()) {
8888
call <- caller_call()
89-
if (is.null(call) || !any(startsWith(as.character(call[[1]]), "scale_"))) {
89+
if (scale_override_call(call)) {
9090
call <- current_call()
9191
}
9292
sc <- continuous_scale(
@@ -113,7 +113,7 @@ scale_y_continuous <- function(name = waiver(), breaks = waiver(),
113113
guide = waiver(), position = "left",
114114
sec.axis = waiver()) {
115115
call <- caller_call()
116-
if (is.null(call) || !any(startsWith(as.character(call[[1]]), "scale_"))) {
116+
if (scale_override_call(call)) {
117117
call <- current_call()
118118
}
119119
sc <- continuous_scale(
@@ -198,3 +198,13 @@ scale_x_sqrt <- function(...) {
198198
scale_y_sqrt <- function(...) {
199199
scale_y_continuous(..., transform = transform_sqrt())
200200
}
201+
202+
# Helpers -----------------------------------------------------------------
203+
204+
scale_override_call <- function(call = NULL) {
205+
if (is.null(call) || is.function(call[[1]])) {
206+
return(TRUE)
207+
}
208+
!any(startsWith(as.character(call[[1]])), "scale_")
209+
}
210+

0 commit comments

Comments
 (0)