Skip to content

Commit

Permalink
Robustification of allowed values for hidden/temporary R options
Browse files Browse the repository at this point in the history
  • Loading branch information
HenrikBengtsson committed Jan 3, 2025
1 parent 1b6f561 commit bed6981
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: matrixStats
Version: 1.4.1-9011
Version: 1.4.1-9012
Depends:
R (>= 3.4.0)
Suggests:
Expand Down
33 changes: 20 additions & 13 deletions R/000.DEPRECATION.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,17 @@ defunctShouldBeMatrixOrVector <- function(x) {
.Defunct(msg = sprintf("[%s] Argument %s is of class %s, but should be a matrix or a vector. The use of a %s is not supported, the correctness of the result is not guaranteed. Please update your code accordingly.", .packageName, x_name, x_class, x_class)) #nolint
}

validateScalarCenter <- function(center, n, dimname) {
onScalar <- getOption("matrixStats.center.onScalar", "defunct")
if (identical(onScalar, "ignore")) {
stop("R option 'matrixStats.center.onScalar' must not be \"ignore\"; only valid options are \"defunct\" (default) or \"deprecated\"")
}

validateScalarCenter <- function(center, n, dimname) { onScalar <- getOption("matrixStats.center.onScalar", "defunct")
action <- switch(onScalar,
deprecated = .Deprecated,
defunct = .Defunct,
.Defunct
NULL
)

if (is.null(action)) {
stop(sprintf("R option 'matrixStats.center.onScalar' must not be \"%s\"; the only valid values are \"defunct\" and \"deprecated\"", onScalar))
}

msg <- sprintf("[%s (>= 0.58.0)] Argument '%s' should be of the same length as number of %s of '%s'. Use of a scalar value is %s: %s != %s (See also ?matrixStats::matrixStats.options)", .packageName, "center", dimname, "x", onScalar, length(center), n)
action(msg = msg, package = .packageName)
}
Expand Down Expand Up @@ -67,13 +66,16 @@ centerOnUse <- function(fcnname, calls = sys.calls(), msg = NULL) {
value <- getOption("matrixStats.center.onUse", "ignore")
if (identical(value, "ignore")) return()

value <- match.arg(value, c("deprecated", "defunct"))
action <- switch(value,
deprecated = .Deprecated,
defunct = .Defunct,
function(...) NULL
NULL
)

if (is.null(action)) {
stop(sprintf("R option 'matrixStats.center.onScalar' must not be \"%s\"; the only valid values are \"defunct\", \"deprecated\", and \"ignore\"", value))
}

if (is.null(msg)) {
msg <- sprintf("[%s] Argument '%s' of %s::%s() is %s: %s (See also ?matrixStats::matrixStats.options)",
.packageName, "center", .packageName, fcnname,
Expand Down Expand Up @@ -115,17 +117,22 @@ validateTiesMethodMissing <- local({

tiesMethodMissing <- local({
function() {
action <- getOption("matrixStats.ties.method.missing", if (getRversion() >= "4.4.0") "deprecated" else "ignore")
if (action == "ignore") return()
value <- getOption("matrixStats.ties.method.missing", if (getRversion() >= "4.4.0") "deprecated" else "ignore")
if (value == "ignore") return()

## How often should we check?
if (!validateTiesMethodMissing()) return()

action <- switch(action,
action <- switch(value,
deprecated = .Deprecated,
defunct = .Defunct,
function(...) NULL
NULL
)

if (is.null(action)) {
stop(sprintf("R option 'matrixStats.ties.method.missing' must not be \"%s\"; the only valid values are \"defunct\", \"deprecated\", and \"ignore\"", value))
}

msg <- sprintf("[%s (>= 1.3.0)] Please explicitly specify argument 'ties.method' when calling colRanks() and rowRanks() of %s. This is because the current default ties.method=\"max\" will eventually be updated to ties.method=\"average\" in order to align with the default of base::rank(). If you are an end-user that cannot update the R code causing this, see ?matrixStats::matrixStats.options for how to temporarily disable this check", .packageName, .packageName)
action(msg = msg, package = .packageName)
}
Expand Down

0 comments on commit bed6981

Please sign in to comment.