From 20a7e6b112a92dbcb0a795f97401db6eaef33a42 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Wed, 11 Jun 2025 09:35:11 +0200 Subject: [PATCH 1/2] separate logic for complex structures --- R/scale-.R | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/R/scale-.R b/R/scale-.R index 37cb65d400..018ac2e20a 100644 --- a/R/scale-.R +++ b/R/scale-.R @@ -1315,7 +1315,11 @@ ScaleDiscrete <- ggproto("ScaleDiscrete", Scale, if (!is_null(pal_names)) { # if pal is named, limit the pal by the names first, # then limit the values by the pal - vec_slice(pal, is.na(match(pal_names, limits))) <- na_value + if (is.null(dim(pal))) { + pal[is.na(match(pal_names, limits))] <- na_value + } else { + vec_slice(pal, is.na(match(pal_names, limits))) <- na_value + } pal <- vec_set_names(pal, NULL) limits <- pal_names } From c0d08e2ad4363e9139c62df60ed0bd308ccc6ac7 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Wed, 11 Jun 2025 09:43:22 +0200 Subject: [PATCH 2/2] use `is_null` --- R/scale-.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/scale-.R b/R/scale-.R index 018ac2e20a..ae2100a0d3 100644 --- a/R/scale-.R +++ b/R/scale-.R @@ -1315,7 +1315,7 @@ ScaleDiscrete <- ggproto("ScaleDiscrete", Scale, if (!is_null(pal_names)) { # if pal is named, limit the pal by the names first, # then limit the values by the pal - if (is.null(dim(pal))) { + if (is_null(dim(pal))) { pal[is.na(match(pal_names, limits))] <- na_value } else { vec_slice(pal, is.na(match(pal_names, limits))) <- na_value