From 9c72c979b7c7ae04e80f71bf5ad5a2ff7d21484f Mon Sep 17 00:00:00 2001 From: Henrik Bengtsson Date: Tue, 25 May 2021 16:08:16 -0700 Subject: [PATCH] Harmonize error messages [#202] --- R/000.DEPRECATION.R | 4 ++-- R/benchmark.R | 2 +- R/binCounts.R | 8 ++++---- R/binMeans.R | 19 +++++++++---------- R/diff2.R | 4 ++-- R/mean2.R | 6 +++--- R/rowAvgsPerColSet.R | 20 ++++++++++---------- R/rowCounts.R | 12 ++++++------ R/rowMads.R | 4 ++-- R/rowOrderStats.R | 4 ++-- R/rowProds.R | 4 ++-- R/rowQuantiles.R | 8 ++++---- R/rowRanks.R | 4 ++-- R/rowTabulates.R | 4 ++-- R/rowVars.R | 4 ++-- R/rowWeightedMeans.R | 12 ++++++------ R/rowWeightedMedians.R | 12 ++++++------ R/sum2.R | 6 +++--- R/varDiff.R | 8 ++++---- R/weightedMad.R | 14 +++++++------- R/weightedMedian.R | 2 +- R/weightedVar.R | 2 +- R/x_OP_y.R | 4 ++-- 23 files changed, 83 insertions(+), 84 deletions(-) diff --git a/R/000.DEPRECATION.R b/R/000.DEPRECATION.R index 50cd1751..70468975 100644 --- a/R/000.DEPRECATION.R +++ b/R/000.DEPRECATION.R @@ -9,7 +9,7 @@ validateScalarCenter <- function(center, n, dimname) { ## Nothing to do? if (is.null(fcn)) return() - msg <- sprintf("Argument 'center' should be of the same length as number of %s of 'x'. Use of a scalar value is deprecated: %s != %s", dimname, length(center), n) + msg <- sprintf("Argument '%s' should be of the same length as number of %s of '%s'. Use of a scalar value is deprecated: %s != %s", "center", dimname, "x", length(center), n) fcn(msg = msg, package = .packageName) } @@ -51,7 +51,7 @@ centerOnUse <- function(fcnname, calls = sys.calls(), msg = NULL) { fcn <- switch(value, deprecated = .Deprecated, defunct = .Defunct) if (is.null(msg)) { - msg <- sprintf("Argument 'center' of %s::%s() is %s: %s", + msg <- sprintf("Argument '%s' of %s::%s() is %s: %s", "center", .packageName, fcnname, value, deparse(calls[[1]])[1]) } diff --git a/R/benchmark.R b/R/benchmark.R index 7cd659d6..92bc0b3c 100644 --- a/R/benchmark.R +++ b/R/benchmark.R @@ -1,6 +1,6 @@ benchmark <- function(fcn, tags = NULL, path = NULL, workdir = "reports", envir = parent.frame(), ...) { - requireNamespace("R.rsp") || stop("R.rsp not installed") + requireNamespace("R.rsp") || stop(sprintf("Package %s is not installed", "R.rsp")) if (is.function(fcn)) { fcn <- deparse(substitute(fcn)) diff --git a/R/binCounts.R b/R/binCounts.R index 3e450d2a..c97c3a3a 100644 --- a/R/binCounts.R +++ b/R/binCounts.R @@ -50,18 +50,18 @@ binCounts <- function(x, idxs = NULL, bx, right = FALSE, ...) { # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Argument 'x': if (!is.numeric(x)) { - stop(sprintf("Argument 'x' is not numeric: %s", mode(x))) + stop(sprintf("Argument '%s' is not numeric: %s", "x", mode(x))) } # Argument 'bx': if (!is.numeric(bx)) { - stop(sprintf("Argument 'bx' is not numeric: %s", mode(bx))) + stop(sprintf("Argument '%s' is not numeric: %s", "bx", mode(bx))) } if (any(is.infinite(bx))) { - stop("Argument 'bx' must not contain Inf values") + stop(sprintf("Argument '%s' must not contain Inf values", "bx")) } if (is.unsorted(bx)) { - stop("Argument 'bx' is not ordered") + stop(sprintf("Argument '%s' is not ordered", "bx")) } # Apply subset diff --git a/R/binMeans.R b/R/binMeans.R index 73634c52..529159c9 100644 --- a/R/binMeans.R +++ b/R/binMeans.R @@ -59,41 +59,40 @@ binMeans <- function(y, x, idxs = NULL, bx, na.rm = TRUE, count = TRUE, # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Argument 'y': if (!is.numeric(y) && !is.logical(y)) { - stop(sprintf("Argument 'y' is neither numeric nor logical: %s", mode(y))) + stop(sprintf("Argument '%s' is neither numeric nor logical: %s", "y", mode(y))) } if (is.numeric(y) && !is.integer(y) && any(is.infinite(y))) { - stop("Argument 'y' must not contain infinite values") + stop(sprintf("Argument '%s' must not contain infinite values", "y")) } n <- length(y) # Argument 'x': if (!is.numeric(x)) { - stop(sprintf("Argument 'x' is not numeric: %s", mode(x))) + stop(sprintf("Argument '%s' is not numeric: %s", "x", mode(x))) } if (length(x) != n) { - stop(sprintf("Argument 'y' and 'x' are of different lengths: %.0f != %.0f", - length(y), length(x))) + stop(sprintf("Argument '%s' and '%s' are of different lengths: %.0f != %.0f", "y", "x", length(y), length(x))) } # Argument 'bx': if (!is.numeric(bx)) { - stop(sprintf("Argument 'bx' is not numeric: %s", mode(bx))) + stop(sprintf("Argument '%s' is not numeric: %s", "bx", mode(bx))) } if (any(is.infinite(bx))) { - stop("Argument 'bx' must not contain Inf values") + stop(sprintf("Argument '%s' must not contain Inf values", "bx")) } if (is.unsorted(bx)) { - stop("Argument 'bx' is not ordered") + stop(sprintf("Argument '%s' is not ordered", "bx")) } # Argument 'na.rm': if (!is.logical(na.rm)) { - stop(sprintf("Argument 'na.rm' is not logical: %s", mode(na.rm))) + stop(sprintf("Argument '%s' is not logical: %s", "na.rm", mode(na.rm))) } # Argument 'count': if (!is.logical(count)) { - stop(sprintf("Argument 'count' is not logical: %s", mode(count))) + stop(sprintf("Argument '%s' is not logical: %s", "count", mode(count))) } # Apply subset diff --git a/R/diff2.R b/R/diff2.R index fd397011..5b53b3bb 100644 --- a/R/diff2.R +++ b/R/diff2.R @@ -33,12 +33,12 @@ diff2 <- function(x, idxs = NULL, lag = 1L, differences = 1L, ...) { # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Argument 'lag': if (length(lag) != 1L) { - stop(sprintf("Argument 'lag' is not a scalar: %.0f", length(lag))) + stop(sprintf("Argument '%s' is not a scalar: %.0f", "lag", length(lag))) } # Argument 'differences': if (length(differences) != 1L) { - stop(sprintf("Argument 'differences' is not a scalar: %.0f", length(differences))) + stop(sprintf("Argument '%s' is not a scalar: %.0f", "differences", length(differences))) } lag <- as.integer(lag) diff --git a/R/mean2.R b/R/mean2.R index f94e2b76..e41751a3 100644 --- a/R/mean2.R +++ b/R/mean2.R @@ -46,17 +46,17 @@ mean2 <- function(x, idxs = NULL, na.rm = FALSE, refine = TRUE, ...) { # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Argument 'x': if (!is.numeric(x) && !is.logical(x)) { - stop(sprintf("Argument 'x' is neither numeric nor logical: %s", mode(x))) + stop(sprintf("Argument '%s' is neither numeric nor logical: %s", "x", mode(x))) } # Argument 'na.rm': if (!is.logical(na.rm)) { - stop(sprintf("Argument 'na.rm' is not logical: %s", mode(na.rm))) + stop(sprintf("Argument '%s' is not logical: %s", "na.rm", mode(na.rm))) } # Argument 'refine': if (!is.logical(refine)) { - stop(sprintf("Argument 'refine' is not logical: %s", mode(refine))) + stop(sprintf("Argument '%s' is not logical: %s", "refine", mode(refine))) } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/R/rowAvgsPerColSet.R b/R/rowAvgsPerColSet.R index b1a57151..06a7b514 100644 --- a/R/rowAvgsPerColSet.R +++ b/R/rowAvgsPerColSet.R @@ -56,7 +56,7 @@ rowAvgsPerColSet <- function(X, W = NULL, rows = NULL, S, # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Argument 'X': if (!is.matrix(X)) { - stop(sprintf("Argument 'X' is not a matrix: %s", class(X)[1L])) + stop(sprintf("Argument '%s' is not a matrix: %s", "X", class(X)[1L])) } dimX <- dim(X) @@ -64,27 +64,27 @@ rowAvgsPerColSet <- function(X, W = NULL, rows = NULL, S, hasW <- !is.null(W) if (hasW) { if (!is.matrix(W)) { - stop(sprintf("Argument 'W' is not a matrix: %s", class(W)[1L])) + stop(sprintf("Argument '%s' is not a matrix: %s", "W", class(W)[1L])) } if (any(dim(W) != dimX)) { - stop(sprintf("Argument 'W' does not have the same dimension as 'X': %s != %s", - paste(dim(W), collapse = "x"), paste(dimX, collapse = "x"))) + stop(sprintf("Argument '%s' does not have the same dimension as '%s': %s != %s", + "W", "X", paste(dim(W), collapse = "x"), paste(dimX, collapse = "x"))) } if (!is.numeric(W)) { - stop(sprintf("Argument 'W' is not numeric: %s", mode(W))) + stop(sprintf("Argument '%s' is not numeric: %s", "W", mode(W))) } } # Argument 'S': if (!is.matrix(S)) { - stop(sprintf("Argument 'S' is not a matrix: %s", class(S)[1L])) + stop(sprintf("Argument '%s' is not a matrix: %s", "S", class(S)[1L])) } nbrOfSets <- ncol(S) setNames <- colnames(S) # Argument 'FUN': if (!is.function(FUN)) { - stop(sprintf("Argument 'FUN' is not a function: %s", mode(S))) + stop(sprintf("Argument '%s' is not a function: %s", "FUN", mode(S))) } # Apply subset @@ -159,19 +159,19 @@ colAvgsPerRowSet <- function(X, W = NULL, cols = NULL, S, # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Argument 'X': if (!is.matrix(X)) { - stop(sprintf("Argument 'X' is not a matrix: %s", class(X)[1L])) + stop(sprintf("Argument '%s' is not a matrix: %s", "X", class(X)[1L])) } # Argument 'W': # Argument 'S': if (!is.matrix(S)) { - stop(sprintf("Argument 'S' is not a matrix: %s", class(S)[1L])) + stop(sprintf("Argument '%s' is not a matrix: %s", "S", class(S)[1L])) } # Argument 'FUN': if (!is.function(FUN)) { - stop(sprintf("Argument 'FUN' is not a function: %s", mode(S))) + stop(sprintf("Argument '%s' is not a function: %s", "FUN", mode(S))) } # Apply subset diff --git a/R/rowCounts.R b/R/rowCounts.R index 51b5d9bb..3fa72802 100644 --- a/R/rowCounts.R +++ b/R/rowCounts.R @@ -43,7 +43,7 @@ rowCounts <- function(x, rows = NULL, cols = NULL, value = TRUE, if (is.matrix(x)) { } else if (is.vector(x)) { } else { - stop(sprintf("Argument 'x' must be a matrix or a vector: %s", mode(x)[1L])) + stop(sprintf("Argument '%s' must be a matrix or a vector: %s", "x", mode(x)[1L])) } # Argument 'dim.': @@ -51,7 +51,7 @@ rowCounts <- function(x, rows = NULL, cols = NULL, value = TRUE, # Argument 'value': if (length(value) != 1L) { - stop(sprintf("Argument 'value' has to be a single value: %.0f", length(value))) + stop(sprintf("Argument '%s' has to be a single value: %.0f", "value", length(value))) } # Coerce 'value' to matrix @@ -97,7 +97,7 @@ colCounts <- function(x, rows = NULL, cols = NULL, value = TRUE, if (is.matrix(x)) { } else if (is.vector(x)) { } else { - stop(sprintf("Argument 'x' must be a matrix or a vector: %s", mode(x)[1L])) + stop(sprintf("Argument '%s' must be a matrix or a vector: %s", "x", mode(x)[1L])) } # Argument 'dim.': @@ -105,7 +105,7 @@ colCounts <- function(x, rows = NULL, cols = NULL, value = TRUE, # Argument 'value': if (length(value) != 1L) { - stop(sprintf("Argument 'value' has to be a single value: %.0f", length(value))) + stop(sprintf("Argument '%s' has to be a single value: %.0f", "value", length(value))) } # Coerce 'value' to matrix @@ -148,12 +148,12 @@ colCounts <- function(x, rows = NULL, cols = NULL, value = TRUE, count <- function(x, idxs = NULL, value = TRUE, na.rm = FALSE, ...) { # Argument 'x': if (!is.vector(x)) { - stop(sprintf("Argument 'x' must be a vector: %s", mode(x)[1L])) + stop(sprintf("Argument '%s' must be a vector: %s", "x", mode(x)[1L])) } # Argument 'value': if (length(value) != 1L) { - stop(sprintf("Argument 'value' has to be a single value: %.0f", length(value))) + stop(sprintf("Argument '%s' has to be a single value: %.0f", "value", length(value))) } # Coerce 'value' to matrix diff --git a/R/rowMads.R b/R/rowMads.R index 61170033..5024b0a9 100644 --- a/R/rowMads.R +++ b/R/rowMads.R @@ -23,7 +23,7 @@ rowMads <- function(x, rows = NULL, cols = NULL, center = NULL, if (length(center) == 1L && is.null(rows)) { validateScalarCenter(center, nrow(x), "rows") } else { - stop(sprintf("Argument 'center' should be of the same length as number of rows of 'x': %d != %d", length(center), nrow(x))) + stop(sprintf("Argument '%s' should be of the same length as number of rows of '%s': %d != %d", "center", "x", length(center), nrow(x))) } } if (!is.null(rows)) center <- center[rows] @@ -67,7 +67,7 @@ colMads <- function(x, rows = NULL, cols = NULL, center = NULL, if (length(center) == 1L && is.null(cols)) { validateScalarCenter(center, ncol(x), "columns") } else { - stop(sprintf("Argument 'center' should be of the same length as number of columns of 'x': %d != %d", length(center), ncol(x))) + stop(sprintf("Argument '%s' should be of the same length as number of columns of '%s': %d != %d", "center", "x", length(center), ncol(x))) } } if (!is.null(cols)) center <- center[cols] diff --git a/R/rowOrderStats.R b/R/rowOrderStats.R index c66f1ceb..1126578b 100644 --- a/R/rowOrderStats.R +++ b/R/rowOrderStats.R @@ -43,7 +43,7 @@ rowOrderStats <- function(x, rows = NULL, cols = NULL, which, # Check missing values if (anyMissing(x)) { - stop("Argument 'x' must not contain missing value") + stop(sprintf("Argument '%s' must not contain missing value", "x")) } which <- as.integer(which) @@ -59,7 +59,7 @@ colOrderStats <- function(x, rows = NULL, cols = NULL, which, # Check missing values if (anyMissing(x)) { - stop("Argument 'x' must not contain missing value") + stop(sprintf("Argument '%s' must not contain missing value", "x")) } which <- as.integer(which) diff --git a/R/rowProds.R b/R/rowProds.R index 6d742a0c..ae414df1 100644 --- a/R/rowProds.R +++ b/R/rowProds.R @@ -65,7 +65,7 @@ rowProds <- function(x, rows = NULL, cols = NULL, na.rm = FALSE, prod <- product } else if (method == "direct") { } else { - stop(sprintf("Unknown value of argument 'method': %s", method)) + stop(sprintf("Unknown value of argument '%s': %s", "method", method)) } for (ii in seq_len(n)) { @@ -105,7 +105,7 @@ colProds <- function(x, rows = NULL, cols = NULL, na.rm = FALSE, prod <- product } else if (method == "direct") { } else { - stop(sprintf("Unknown value of argument 'method': %s", method)) + stop(sprintf("Unknown value of argument '%s': %s", "method", method)) } for (ii in seq_len(n)) { diff --git a/R/rowQuantiles.R b/R/rowQuantiles.R index 3b5d0e19..6e053232 100644 --- a/R/rowQuantiles.R +++ b/R/rowQuantiles.R @@ -48,11 +48,11 @@ rowQuantiles <- function(x, rows = NULL, cols = NULL, # Argument 'probs': if (anyMissing(probs)) { - stop("Argument 'probs' contains missing values") + stop(sprintf("Argument '%s' contains missing values", "probs")) } eps <- 100 * .Machine$double.eps if (any((probs < -eps | probs > 1 + eps))) { - stop("Argument 'probs' is out of range [0-eps, 1+eps]") + stop(sprintf("Argument '%s' is out of range [0-eps, 1+eps]", "probs")) } # Apply subset @@ -168,11 +168,11 @@ colQuantiles <- function(x, rows = NULL, cols = NULL, # Argument 'probs': if (anyMissing(probs)) { - stop("Argument 'probs' contains missing values") + stop(sprintf("Argument '%s' contains missing values", "probs")) } eps <- 100 * .Machine$double.eps if (any((probs < -eps | probs > 1 + eps))) { - stop("Argument 'probs' is out of range [0-eps, 1+eps]") + stop(sprintf("Argument '%s' is out of range [0-eps, 1+eps]", "probs")) } # Apply subset diff --git a/R/rowRanks.R b/R/rowRanks.R index 786d7093..10662318 100644 --- a/R/rowRanks.R +++ b/R/rowRanks.R @@ -106,7 +106,7 @@ rowRanks <- function(x, rows = NULL, cols = NULL, ties_method <- charmatch(ties.method, c("average", "first", "last", "random", "max", "min", "dense"), nomatch = 0L) if (ties_method == 0L) { - stop(sprintf("Unknown value of argument 'ties.method': %s", ties.method)) + stop(sprintf("Unknown value of argument '%s': %s", "ties.method", ties.method)) } dim. <- as.integer(dim.) @@ -131,7 +131,7 @@ colRanks <- function(x, rows = NULL, cols = NULL, ties_method <- charmatch(ties.method, c("average", "first", "last", "random", "max", "min", "dense"), nomatch = 0L) if (ties_method == 0L) { - stop(sprintf("Unknown value of argument 'ties.method': %s", ties.method)) + stop(sprintf("Unknown value of argument '%s': %s", "ties.method", ties.method)) } dim. <- as.integer(dim.) diff --git a/R/rowTabulates.R b/R/rowTabulates.R index e65c960b..40e7d5fb 100644 --- a/R/rowTabulates.R +++ b/R/rowTabulates.R @@ -41,7 +41,7 @@ rowTabulates <- function(x, rows = NULL, cols = NULL, values = NULL, ...) { } else if (is.logical(x)) { } else if (is.raw(x)) { } else { - stop(sprintf("Argument 'x' must be of type integer, logical, or raw: %s", class(x)[1])) + stop(sprintf("Argument '%s' must be of type integer, logical, or raw: %s", "x", class(x)[1])) } # Apply subset @@ -98,7 +98,7 @@ colTabulates <- function(x, rows = NULL, cols = NULL, values = NULL, ...) { } else if (is.logical(x)) { } else if (is.raw(x)) { } else { - stop(sprintf("Argument 'x' must be of type integer, logical, or raw: %s", class(x)[1])) + stop(sprintf("Argument '%s' must be of type integer, logical, or raw: %s", "x", class(x)[1])) } # Apply subset diff --git a/R/rowVars.R b/R/rowVars.R index 913a1e4d..d101a61c 100644 --- a/R/rowVars.R +++ b/R/rowVars.R @@ -59,7 +59,7 @@ rowVars <- function(x, rows = NULL, cols = NULL, na.rm = FALSE, center = NULL, validateScalarCenter(center, nrow(x), "rows") center <- rep(center, times = nrow(x)) } else { - stop(sprintf("Argument 'center' should be of the same length as number of rows of 'x': %d != %d", length(center), nrow(x))) + stop(sprintf("Argument '%s' should be of the same length as number of rows of '%s': %d != %d", "center", "x", length(center), nrow(x))) } } if (!is.null(rows)) center <- center[rows] @@ -170,7 +170,7 @@ colVars <- function(x, rows = NULL, cols = NULL, na.rm = FALSE, center = NULL, validateScalarCenter(center, ncol(x), "columns") center <- rep(center, times = ncol(x)) } else { - stop(sprintf("Argument 'center' should be of the same length as number of columns of 'x': %d != %d", length(center), ncol(x))) + stop(sprintf("Argument '%s' should be of the same length as number of columns of '%s': %d != %d", "center", "x", length(center), ncol(x))) } } if (!is.null(cols)) center <- center[cols] diff --git a/R/rowWeightedMeans.R b/R/rowWeightedMeans.R index 291054eb..18e1ce1f 100644 --- a/R/rowWeightedMeans.R +++ b/R/rowWeightedMeans.R @@ -48,13 +48,13 @@ rowWeightedMeans <- function(x, w = NULL, rows = NULL, cols = NULL, if (has_weights) { n <- ncol(x) if (length(w) != n) { - stop(sprintf("The length of argument 'w' is does not match the number of column in 'x': %d != %d", length(w), n)) #nolint + stop(sprintf("The length of argument '%s' does not match the number of column in '%s': %d != %d", "w", "x", length(w), n)) #nolint } if (!is.numeric(w)) { - stop(sprintf("Argument 'w' is not numeric: %s", mode(w))) + stop(sprintf("Argument '%s' is not numeric: %s", "w", mode(w))) } if (any(!is.na(w) & w < 0)) { - stop("Argument 'w' has negative weights") + stop(sprintf("Argument '%s' has negative weights", "w")) } } @@ -148,13 +148,13 @@ colWeightedMeans <- function(x, w = NULL, rows = NULL, cols = NULL, if (has_weights) { n <- nrow(x) if (length(w) != n) { - stop(sprintf("The length of argument 'w' is does not match the number of rows in 'x': %d != %d", length(w), n)) #nolint + stop(sprintf("The length of argument '%s' does not match the number of rows in '%s': %d != %d", "w", "x", length(w), n)) #nolint } if (!is.numeric(w)) { - stop(sprintf("Argument 'w' is not numeric: %s", mode(w))) + stop(sprintf("Argument '%s' is not numeric: %s", "w", mode(w))) } if (any(!is.na(w) & w < 0)) { - stop("Argument 'w' has negative weights") + stop(sprintf("Argument '%s' has negative weights", "w")) } } diff --git a/R/rowWeightedMedians.R b/R/rowWeightedMedians.R index a7bcfb43..12d057cb 100644 --- a/R/rowWeightedMedians.R +++ b/R/rowWeightedMedians.R @@ -48,13 +48,13 @@ rowWeightedMedians <- function(x, w = NULL, rows = NULL, cols = NULL, if (has_weights) { n <- ncol(x) if (length(w) != n) { - stop(sprintf("The length of argument 'w' is does not match the number of column in 'x': %d != %d", length(w), n)) #nolint + stop(sprintf("The length of argument '%s' does not match the number of rows in '%s': %d != %d", "w", "x", length(w), n)) #nolint } if (!is.numeric(w)) { - stop(sprintf("Argument 'w' is not numeric: %s", mode(w))) + stop(sprintf("Argument '%s' is not numeric: %s", "w", mode(w))) } if (any(!is.na(w) & w < 0)) { - stop("Argument 'w' has negative weights") + stop(sprintf("Argument '%s' has negative weights", "w")) } } @@ -103,13 +103,13 @@ colWeightedMedians <- function(x, w = NULL, rows = NULL, cols = NULL, if (has_weights) { n <- nrow(x) if (length(w) != n) { - stop(sprintf("The length of argument 'w' is does not match the number of rows in 'x': %d != %d", length(w), n)) #nolint + stop(sprintf("The length of argument '%s' does not match the number of rows in '%s': %d != %d", "w", "x", length(w), n)) #nolint } if (!is.numeric(w)) { - stop(sprintf("Argument 'w' is not numeric: %s", mode(w))) + stop(sprintf("Argument '%s' is not numeric: %s", "w", mode(w))) } if (any(!is.na(w) & w < 0)) { - stop("Argument 'w' has negative weights") + stop(sprintf("Argument '%s' has negative weights", "w")) } } diff --git a/R/sum2.R b/R/sum2.R index 9d91ec51..0fac25c0 100644 --- a/R/sum2.R +++ b/R/sum2.R @@ -57,12 +57,12 @@ sum2 <- function(x, idxs = NULL, na.rm = FALSE, mode = typeof(x), ...) { x_mode <- typeof(x) x_logical <- (x_mode == "logical") if (!is.numeric(x) && !x_logical) { - stop(sprintf("Argument 'x' is neither numeric nor logical: %s", x_mode)) + stop(sprintf("Argument '%s' is neither numeric nor logical: %s", "x", x_mode)) } # Argument 'na.rm': if (!is.logical(na.rm)) { - stop(sprintf("Argument 'na.rm' is not logical: %s", mode(na.rm))) + stop(sprintf("Argument '%s' is not logical: %s", "na.rm", mode(na.rm))) } # Argument 'mode': @@ -79,7 +79,7 @@ sum2 <- function(x, idxs = NULL, na.rm = FALSE, mode = typeof(x), ...) { } else if (mode == "double") { mode_idx <- 2L } else { - stop(sprintf("Unknown value of argument 'mode': %s", mode)) + stop(sprintf("Unknown value of argument '%s': %s", "mode", mode)) } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/R/varDiff.R b/R/varDiff.R index 1ab6916c..4c546539 100644 --- a/R/varDiff.R +++ b/R/varDiff.R @@ -55,7 +55,7 @@ #' @keywords iteration robust univar #' @export varDiff <- function(x, idxs = NULL, na.rm = FALSE, diff = 1L, trim = 0, ...) { - if (diff < 0L) stop(sprintf("Argument 'diff' must be non-negative: %d", diff)) + if (diff < 0L) stop(sprintf("Argument '%s' must be non-negative: %d", "diff", diff)) # Apply subset if (!is.null(idxs)) x <- x[idxs] @@ -100,7 +100,7 @@ varDiff <- function(x, idxs = NULL, na.rm = FALSE, diff = 1L, trim = 0, ...) { #' @rdname varDiff #' @export sdDiff <- function(x, idxs = NULL, na.rm = FALSE, diff = 1L, trim = 0, ...) { - if (diff < 0L) stop(sprintf("Argument 'diff' must be non-negative: %d", diff)) + if (diff < 0L) stop(sprintf("Argument '%s' must be non-negative: %d", "diff", diff)) # Apply subset if (!is.null(idxs)) x <- x[idxs] @@ -146,7 +146,7 @@ sdDiff <- function(x, idxs = NULL, na.rm = FALSE, diff = 1L, trim = 0, ...) { #' @export madDiff <- function(x, idxs = NULL, na.rm = FALSE, diff = 1L, trim = 0, constant = 1.4826, ...) { - if (diff < 0L) stop(sprintf("Argument 'diff' must be non-negative: %d", diff)) + if (diff < 0L) stop(sprintf("Argument '%s' must be non-negative: %d", "diff", diff)) # Apply subset if (!is.null(idxs)) x <- x[idxs] @@ -191,7 +191,7 @@ madDiff <- function(x, idxs = NULL, na.rm = FALSE, diff = 1L, trim = 0, #' @rdname varDiff #' @export iqrDiff <- function(x, idxs = NULL, na.rm = FALSE, diff = 1L, trim = 0, ...) { - if (diff < 0L) stop(sprintf("Argument 'diff' must be non-negative: %d", diff)) + if (diff < 0L) stop(sprintf("Argument '%s' must be non-negative: %d", "diff", diff)) # Apply subset if (!is.null(idxs)) x <- x[idxs] diff --git a/R/weightedMad.R b/R/weightedMad.R index 34479a22..9a591195 100644 --- a/R/weightedMad.R +++ b/R/weightedMad.R @@ -56,7 +56,7 @@ weightedMad <- function(x, w = NULL, idxs = NULL, na.rm = FALSE, # Argument 'w': if (length(w) != n) { - stop(sprintf("The number of elements in arguments 'w' and 'x' does not match: %.0f != %.0f", length(w), n)) + stop(sprintf("The number of elements in arguments '%s' and '%s' does not match: %.0f != %.0f", "w", "x", length(w), n)) } else if (!is.null(idxs)) { # Apply subset on w w <- w[idxs] @@ -64,11 +64,11 @@ weightedMad <- function(x, w = NULL, idxs = NULL, na.rm = FALSE, # Argument 'constant': if (length(constant) != 1L || !is.numeric(constant)) - stop("Argument 'constant' must be a numeric scalar") + stop(sprintf("Argument '%s' must be a numeric scalar", "constant")) # Argument 'center': if (!is.null(center) && length(center) != 1L) - stop("Argument 'center' must be a scalar or NULL") + stop(sprintf("Argument '%s' must be a scalar or NULL", "center")) # Apply subset on x @@ -156,7 +156,7 @@ rowWeightedMads <- function(x, w = NULL, rows = NULL, cols = NULL, constant = 1.4826, center = NULL, ...) { # Argument 'constant': if (length(constant) != 1L || !is.numeric(constant)) - stop("Argument 'constant' must be a numeric scalar") + stop(sprintf("Argument '%s' must be a numeric scalar", "constant")) # Apply subset on 'center'? if (!is.null(center)) { @@ -166,7 +166,7 @@ rowWeightedMads <- function(x, w = NULL, rows = NULL, cols = NULL, validateScalarCenter(center, nrow(x), "rows") center <- rep(center, times = nrow(x)) } else { - stop(sprintf("Argument 'center' should be of the same length as number of rows of 'x': %d != %d", length(center), nrow(x))) + stop(sprintf("Argument '%s' should be of the same length as number of rows of '%s': %d != %d", "center", "x", length(center), nrow(x))) } } if (!is.null(rows)) center <- center[rows] @@ -202,7 +202,7 @@ colWeightedMads <- function(x, w = NULL, rows = NULL, cols = NULL, constant = 1.4826, center = NULL, ...) { # Argument 'constant': if (length(constant) != 1L || !is.numeric(constant)) - stop("Argument 'constant' must be a numeric scalar") + stop(sprintf("Argument '%s' must be a numeric scalar", "constant")) # Argument 'center': # Apply subset on 'center'? @@ -213,7 +213,7 @@ colWeightedMads <- function(x, w = NULL, rows = NULL, cols = NULL, validateScalarCenter(center, ncol(x), "cols") center <- rep(center, times = ncol(x)) } else { - stop(sprintf("Argument 'center' should be of the same length as number of columns of 'x': %d != %d", length(center), ncol(x))) + stop(sprintf("Argument '%s' should be of the same length as number of columns of '%s': %d != %d", "center", "x", length(center), ncol(x))) } } if (!is.null(cols)) center <- center[cols] diff --git a/R/weightedMedian.R b/R/weightedMedian.R index 658ca81e..0f9c9db4 100644 --- a/R/weightedMedian.R +++ b/R/weightedMedian.R @@ -110,7 +110,7 @@ weightedMedian <- function(x, w = NULL, idxs = NULL, na.rm = FALSE, } else if (ties == "mean") { ties_id <- 8L } else { - stop(sprintf("Unknown value on 'ties': %s", ties)) + stop(sprintf("Unknown value of argument '%s': %s", "ties", ties)) } } diff --git a/R/weightedVar.R b/R/weightedVar.R index 71160bec..dcbe35b8 100644 --- a/R/weightedVar.R +++ b/R/weightedVar.R @@ -59,7 +59,7 @@ weightedVar <- function(x, w = NULL, idxs = NULL, na.rm = FALSE, if (is.null(w)) { w <- rep(1, times = n) } else if (length(w) != n) { - stop(sprintf("The number of elements in arguments 'w' and 'x' does not match: %.0f != %.0f", length(w), n)) + stop(sprintf("The number of elements in arguments '%s' and '%s' does not match: %.0f != %.0f", "w", "x", length(w), n)) } else if (!is.null(idxs)) { # Apply subset on 'w' w <- w[idxs] diff --git a/R/x_OP_y.R b/R/x_OP_y.R index 84182c5b..0764d98f 100644 --- a/R/x_OP_y.R +++ b/R/x_OP_y.R @@ -51,7 +51,7 @@ x_OP_y <- function(x, y, OP, xrows = NULL, xcols = NULL, yidxs = NULL, if (is.character(OP)) { op <- charmatch(OP, c("+", "-", "*", "/"), nomatch = 0L) if (op == 0L) { - stop(sprintf("Unknown value on argument 'OP': %s", sQuote(OP))) + stop(sprintf("Unknown value of argument '%s': %s", "OP", sQuote(OP))) } } else { op <- as.integer(OP) @@ -70,7 +70,7 @@ t_tx_OP_y <- function(x, y, OP, xrows = NULL, xcols = NULL, yidxs = NULL, if (is.character(OP)) { op <- charmatch(OP, c("+", "-", "*", "/"), nomatch = 0L) if (op == 0L) { - stop(sprintf("Unknown value on argument 'OP': %s", sQuote(OP))) + stop(sprintf("Unknown value of argument '%s': %s", "OP", sQuote(OP))) } } else { op <- as.integer(OP)