diff --git a/NAMESPACE b/NAMESPACE index 4405d0ee..b42bbe89 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -12,6 +12,7 @@ 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) @@ -19,6 +20,7 @@ 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) diff --git a/NEWS.md b/NEWS.md index f3fbfb85..4b51d280 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/R/bounds.R b/R/bounds.R index b66059db..f7bca6e0 100644 --- a/R/bounds.R +++ b/R/bounds.R @@ -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 `` are returned unaltered. +#' #' @keywords manip #' @export #' @examples @@ -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 #' @@ -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 `` are returned unaltered. #' @examples #' rescale_mid(1:100, mid = 50.5) #' rescale_mid(runif(50), mid = 0.5) @@ -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 diff --git a/man/rescale.Rd b/man/rescale.Rd index 1383eeea..c41c129e 100644 --- a/man/rescale.Rd +++ b/man/rescale.Rd @@ -8,6 +8,7 @@ \alias{rescale.POSIXt} \alias{rescale.Date} \alias{rescale.integer64} +\alias{rescale.AsIs} \title{Rescale continuous vector to have specified minimum and maximum} \usage{ rescale(x, to, from, ...) @@ -23,6 +24,8 @@ rescale(x, to, from, ...) \method{rescale}{Date}(x, to = c(0, 1), from = range(x, na.rm = TRUE, finite = TRUE), ...) \method{rescale}{integer64}(x, to = c(0, 1), from = range(x, na.rm = TRUE), ...) + +\method{rescale}{AsIs}(x, to, from, ...) } \arguments{ \item{x}{continuous vector of values to manipulate.} @@ -37,6 +40,9 @@ calculated from the range of \code{x}} \description{ Rescale continuous vector to have specified minimum and maximum } +\details{ +Objects of class \verb{} are returned unaltered. +} \examples{ rescale(1:100) rescale(runif(50)) diff --git a/man/rescale_mid.Rd b/man/rescale_mid.Rd index c9bf7392..d3133ab0 100644 --- a/man/rescale_mid.Rd +++ b/man/rescale_mid.Rd @@ -8,6 +8,7 @@ \alias{rescale_mid.POSIXt} \alias{rescale_mid.Date} \alias{rescale_mid.integer64} +\alias{rescale_mid.AsIs} \title{Rescale vector to have specified minimum, midpoint, and maximum} \usage{ rescale_mid(x, to, from, mid, ...) @@ -23,6 +24,8 @@ rescale_mid(x, to, from, mid, ...) \method{rescale_mid}{Date}(x, to = c(0, 1), from = range(x, na.rm = TRUE), mid, ...) \method{rescale_mid}{integer64}(x, to = c(0, 1), from = range(x, na.rm = TRUE), mid = 0, ...) + +\method{rescale_mid}{AsIs}(x, to, from, ...) } \arguments{ \item{x}{vector of values to manipulate.} @@ -39,6 +42,9 @@ calculated from the range of \code{x}} \description{ Rescale vector to have specified minimum, midpoint, and maximum } +\details{ +Objects of class \verb{} are returned unaltered. +} \examples{ rescale_mid(1:100, mid = 50.5) rescale_mid(runif(50), mid = 0.5)