Skip to content

Commit

Permalink
Revert #167
Browse files Browse the repository at this point in the history
As it breaks ggforce and doesn't fix the motivating problem described in #166.
  • Loading branch information
hadley committed Nov 5, 2019
1 parent bb91c06 commit f69c4a7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 20 deletions.
3 changes: 0 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,6 @@
* `date_breaks()` now supports subsecond intervals (@dpseidel, #85).
* `train_continuous()` now maintains the class of inputs when they are not
numeric (@billdenney, #166).
# scales 1.0.0
## New Features
Expand Down
10 changes: 4 additions & 6 deletions R/scale-continuous.r
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ cscale <- function(x, palette, na.value = NA_real_, trans = identity_trans()) {

#' Train (update) a continuous scale
#'
#' Strips attributes and always returns a numeric vector
#'
#' @inheritParams train_discrete
#' @export
train_continuous <- function(new, existing = NULL) {
Expand All @@ -38,12 +40,8 @@ train_continuous <- function(new, existing = NULL) {
if (is.factor(new) || !typeof(new) %in% c("integer", "double")) {
stop("Discrete value supplied to continuous scale", call. = FALSE)
}
# range(NULL, x) strips attributes
if (is.null(existing)) {
suppressWarnings(range(new, na.rm = TRUE, finite = TRUE))
} else {
suppressWarnings(range(existing, new, na.rm = TRUE, finite = TRUE))
}

suppressWarnings(range(existing, new, na.rm = TRUE, finite = TRUE))
}

# Map values for a continuous palette.
Expand Down
2 changes: 1 addition & 1 deletion man/train_continuous.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 5 additions & 10 deletions tests/testthat/test-scale.r
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,11 @@ test_that("train_continuous stops on discrete values", {
)
})

test_that("train_continuous maintains class with `existing=NULL`.", {
expect_equal(
train_continuous(1:5),
c(1, 5)
)
my_date <- as.POSIXct("2018-01-01")
expect_equal(
train_continuous(my_date),
c(my_date, my_date)
)
test_that("train_continuous strips attributes", {
expect_equal(train_continuous(1:5), c(1, 5))

x <- as.Date("1970-01-01") + c(1, 5)
expect_equal(train_continuous(x), c(1, 5))
})

test_that("train_continuous changes class to the class of `existing` when not NULL.", {
Expand Down

0 comments on commit f69c4a7

Please sign in to comment.