@@ -817,6 +817,8 @@ warn_dots_used <- function(env = caller_env(), call = caller_env()) {
817
817
)
818
818
}
819
819
820
+ # TODO: delete shims when {scales} releases >1.3.0.9000
821
+ # and bump {scales} version requirements
820
822
# Shim for scales/#424
821
823
col_mix <- function (a , b , amount = 0.5 ) {
822
824
input <- vec_recycle_common(a = a , b = b , amount = amount )
@@ -829,10 +831,40 @@ col_mix <- function(a, b, amount = 0.5) {
829
831
)
830
832
}
831
833
834
+ # Shim for scales/#427
835
+ as_discrete_pal <- function (x , ... ) {
836
+ if (is.function(x )) {
837
+ return (x )
838
+ }
839
+ pal_manual(x )
840
+ }
841
+
842
+ # Shim for scales/#427
843
+ as_continuous_pal <- function (x , ... ) {
844
+ if (is.function(x )) {
845
+ return (x )
846
+ }
847
+ is_color <- grepl(" ^#(([[:xdigit:]]{2}){3,4}|([[:xdigit:]]){3,4})$" , x ) |
848
+ x %in% grDevices :: colours()
849
+ if (all(is_color )) {
850
+ colour_ramp(x )
851
+ } else {
852
+ approxfun(seq(0 , 1 , length.out = length(x )), x )
853
+ }
854
+ }
855
+
856
+ # Replace shims by actual scales function when available
832
857
on_load({
833
- if (" col_mix" %in% getNamespaceExports(" scales" )) {
858
+ nse <- getNamespaceExports(" scales" )
859
+ if (" col_mix" %in% nse ) {
834
860
col_mix <- scales :: col_mix
835
861
}
862
+ if (" as_discrete_pal" %in% nse ) {
863
+ as_discrete_pal <- scales :: as_discrete_pal
864
+ }
865
+ if (" as_continuous_pal" %in% nse ) {
866
+ as_continuous_pal <- scales :: as_continuous_pal
867
+ }
836
868
})
837
869
838
870
# TODO: Replace me if rlang/#1730 gets implemented
0 commit comments