@@ -861,12 +861,9 @@ ScaleContinuous <- ggproto("ScaleContinuous", Scale,
861
861
labels [lengths(labels ) == 0 ] <- " "
862
862
# Make sure each element is scalar
863
863
labels <- lapply(labels , `[` , 1 )
864
-
865
- if (any(vapply(labels , is.language , logical (1 )))) {
866
- labels <- inject(expression(!!! labels ))
867
- } else {
868
- labels <- unlist(labels )
869
- }
864
+ }
865
+ if (is.expression(labels )) {
866
+ labels <- as.list(labels )
870
867
}
871
868
872
869
labels
@@ -1074,48 +1071,42 @@ ScaleDiscrete <- ggproto("ScaleDiscrete", Scale,
1074
1071
return (NULL )
1075
1072
}
1076
1073
1077
- if (is.null(self $ labels )) {
1074
+ labels <- self $ labels
1075
+ if (is.null(labels )) {
1078
1076
return (NULL )
1079
1077
}
1080
1078
1081
- if (identical(self $ labels , NA )) {
1079
+ if (identical(labels , NA )) {
1082
1080
cli :: cli_abort(
1083
1081
" Invalid {.arg labels} specification. Use {.code NULL}, not {.code NA}." ,
1084
1082
call = self $ call
1085
1083
)
1086
1084
}
1087
1085
1088
- if (is.waiver(self $ labels )) {
1086
+ if (is.waiver(labels )) {
1089
1087
if (! is.null(names(breaks ))) {
1090
- return (names(breaks ))
1091
- }
1092
- if (is.numeric(breaks )) {
1088
+ labels <- names(breaks )
1089
+ } else if (is.numeric(breaks )) {
1093
1090
# Only format numbers, because on Windows, format messes up encoding
1094
- format(breaks , justify = " none" )
1091
+ labels <- format(breaks , justify = " none" )
1095
1092
} else {
1096
- as.character(breaks )
1093
+ labels <- as.character(breaks )
1097
1094
}
1098
- } else if (is.function(self $ labels )) {
1099
- self $ labels(breaks )
1100
- } else {
1101
- if (! is.null(names(self $ labels ))) {
1102
- # If labels have names, use them to match with breaks
1103
- labels <- breaks
1104
-
1105
- map <- match(names(self $ labels ), labels , nomatch = 0 )
1106
- labels [map ] <- self $ labels [map != 0 ]
1107
- labels
1108
- } else {
1109
- labels <- self $ labels
1095
+ } else if (is.function(labels )) {
1096
+ labels <- labels(breaks )
1097
+ } else if (! is.null(names(labels ))) {
1098
+ # If labels have names, use them to match with breaks
1099
+ map <- match(names(self $ labels ), breaks , nomatch = 0 )
1100
+ labels <- replace(breaks , map , labels [map != 0 ])
1101
+ } else if (! is.null(attr(breaks , " pos" ))) {
1102
+ # Need to ensure that if breaks were dropped, corresponding labels are too
1103
+ labels <- labels [attr(breaks , " pos" )]
1104
+ }
1110
1105
1111
- # Need to ensure that if breaks were dropped, corresponding labels are too
1112
- pos <- attr(breaks , " pos" )
1113
- if (! is.null(pos )) {
1114
- labels <- labels [pos ]
1115
- }
1116
- labels
1117
- }
1106
+ if (is.expression(labels )) {
1107
+ labels <- as.list(labels )
1118
1108
}
1109
+ labels
1119
1110
},
1120
1111
1121
1112
clone = function (self ) {
@@ -1351,6 +1342,9 @@ ScaleBinned <- ggproto("ScaleBinned", Scale,
1351
1342
call = self $ call
1352
1343
)
1353
1344
}
1345
+ if (is.expression(labels )) {
1346
+ labels <- as.list(labels )
1347
+ }
1354
1348
labels
1355
1349
},
1356
1350
0 commit comments