Skip to content

Commit

Permalink
<AsIs> methods for rescale()
Browse files Browse the repository at this point in the history
  • Loading branch information
teunbrand committed Nov 1, 2023
1 parent 432432e commit 02d42d9
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ S3method(offset_by,numeric)
S3method(plot,trans)
S3method(print,trans)
S3method(rescale,"NULL")
S3method(rescale,AsIs)
S3method(rescale,Date)
S3method(rescale,POSIXt)
S3method(rescale,dist)
S3method(rescale,integer64)
S3method(rescale,logical)
S3method(rescale,numeric)
S3method(rescale_mid,"NULL")
S3method(rescale_mid,AsIs)
S3method(rescale_mid,Date)
S3method(rescale_mid,POSIXt)
S3method(rescale_mid,dist)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
(@teunbrand, #369).
* Training on factor data no longer sorts the range after multiple training
passes (#383)
* `rescale(I(x), ...)` and `rescale_mid(I(x), ...)` return `I(x)` unaltered
(@teunbrand, #403).

# scales 1.2.1

Expand Down
12 changes: 12 additions & 0 deletions R/bounds.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#' @param from input range (vector of length two). If not given, is
#' calculated from the range of `x`
#' @param ... other arguments passed on to methods
#' @details
#' Objects of class `<AsIs>` are returned unaltered.
#'
#' @keywords manip
#' @export
#' @examples
Expand Down Expand Up @@ -58,6 +61,9 @@ 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.AsIs <- function(x, to, from, ...) x

#' Rescale vector to have specified minimum, midpoint, and maximum
#'
Expand All @@ -68,6 +74,8 @@ rescale.integer64 <- function(x, to = c(0, 1), from = range(x, na.rm = TRUE), ..
#' calculated from the range of `x`
#' @param mid mid-point of input range
#' @param ... other arguments passed on to methods
#' @details
#' Objects of class `<AsIs>` are returned unaltered.
#' @examples
#' rescale_mid(1:100, mid = 50.5)
#' rescale_mid(runif(50), mid = 0.5)
Expand Down Expand Up @@ -129,6 +137,10 @@ rescale_mid.integer64 <- function(x, to = c(0, 1), from = range(x, na.rm = TRUE)
}


#' @rdname rescale_mid
#' @export
rescale_mid.AsIs <- function(x, to, from, ...) x

#' Rescale numeric vector to have specified maximum
#'
#' @export
Expand Down
6 changes: 6 additions & 0 deletions man/rescale.Rd

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

6 changes: 6 additions & 0 deletions man/rescale_mid.Rd

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

0 comments on commit 02d42d9

Please sign in to comment.