Skip to content

Commit

Permalink
Fix #382
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasp85 committed Nov 1, 2023
1 parent 01493b7 commit eeae014
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ S3method(print,trans)
S3method(rescale,"NULL")
S3method(rescale,Date)
S3method(rescale,POSIXt)
S3method(rescale,difftime)
S3method(rescale,dist)
S3method(rescale,integer64)
S3method(rescale,logical)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Attempt to make the sort behavior of the range consistent for character
vectors during training. Mixing of character and factor data will still lead
to different results depending on the training order.
* Add a rescale method for `difftime` objects (#382)

# scales 1.2.1

Expand Down
4 changes: 4 additions & 0 deletions R/bounds.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ rescale.integer64 <- function(x, to = c(0, 1), from = range(x, na.rm = TRUE), ..
(x - from[1]) / diff(from) * diff(to) + to[1]
}

#' @rdname rescale
#' @export
rescale.difftime <- rescale.numeric


#' Rescale vector to have specified minimum, midpoint, and maximum
#'
Expand Down
3 changes: 3 additions & 0 deletions man/rescale.Rd

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

2 changes: 1 addition & 1 deletion tests/testthat/test-range.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ test_that("factor discrete ranges stay in order", {
expect_equal(discrete_range(f, f), letters[3:1])
expect_equal(discrete_range(f, "c"), letters[3:1])
expect_equal(discrete_range(f, c("a", "b", "c")), letters[3:1])
expect_equal(discrete_range(f, c("a", "b", "c", NA), na.rm = FALSE), letters[3:1])
expect_equal(discrete_range(f, c("a", "b", "c", NA), na.rm = FALSE), c(letters[3:1], NA))
})

0 comments on commit eeae014

Please sign in to comment.