Skip to content

Commit 97dcbb1

Browse files
committed
Ensure that we don't try and assign scale to NULL
Fixes #2599
1 parent 8922e24 commit 97dcbb1

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

R/scale-type.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
find_scale <- function(aes, x, env) {
1+
find_scale <- function(aes, x, env = parent.frame()) {
2+
if (is.null(x)) {
3+
return(NULL)
4+
}
5+
26
type <- scale_type(x)
37
candidates <- paste("scale", aes, type, sep = "_")
48

tests/testthat/test-scale-type.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
context("test-scale-type.R")
2+
3+
test_that("no scale for NULL aesthetic", {
4+
expect_equal(find_scale("colour", NULL), NULL)
5+
})
6+
7+
test_that("message + continuous for unknown type", {
8+
x <- structure(1:10, class = "ggplot2_foo")
9+
10+
expect_message(scale <- find_scale("colour", x), "ggplot2_foo")
11+
expect_s3_class(scale, "ScaleContinuous")
12+
})

0 commit comments

Comments
 (0)