Skip to content

Commit

Permalink
Remove remaining is.na(useNames) [#246]
Browse files Browse the repository at this point in the history
  • Loading branch information
HenrikBengtsson committed Dec 28, 2024
1 parent 70c356d commit f658bb3
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 37 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-9006
Version: 1.4.1-9007
Depends:
R (>= 3.4.0)
Suggests:
Expand Down
8 changes: 4 additions & 4 deletions R/rowAlls.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ rowAlls <- function(x, rows = NULL, cols = NULL, value = TRUE,
z <- (x == value)
dim <- dim(x) # for 0xN and Mx0 cases; needed in R (< 3.4.0)
if (!identical(dim(z), as.integer(dim))) dim(z) <- dim
if (isTRUE(useNames)) dimnames(z) <- dimnames(x)
if (useNames) dimnames(z) <- dimnames(x)
return(rowAlls(z, na.rm = na.rm, dim. = dim., ..., useNames = useNames))
}
}
Expand Down Expand Up @@ -156,7 +156,7 @@ colAlls <- function(x, rows = NULL, cols = NULL, value = TRUE,
z <- (x == value)
dim <- dim(x) # for 0xN and Mx0 cases; needed in R (< 3.4.0)
if (!identical(dim(z), as.integer(dim))) dim(z) <- dim
if (isTRUE(useNames)) dimnames(z) <- dimnames(x)
if (useNames) dimnames(z) <- dimnames(x)
return(colAlls(z, na.rm = na.rm, dim. = dim., ..., useNames = useNames))
}
}
Expand Down Expand Up @@ -231,7 +231,7 @@ rowAnys <- function(x, rows = NULL, cols = NULL, value = TRUE,
z <- (x == value)
dim <- dim(x) # for 0xN and Mx0 cases; needed in R (< 3.4.0)
if (!identical(dim(z), as.integer(dim))) dim(z) <- dim
if (isTRUE(useNames)) dimnames(z) <- dimnames(x)
if (useNames) dimnames(z) <- dimnames(x)
return(rowAnys(z, na.rm = na.rm, dim. = dim., ..., useNames = useNames))
}
}
Expand Down Expand Up @@ -276,7 +276,7 @@ colAnys <- function(x, rows = NULL, cols = NULL, value = TRUE,
z <- (x == value)
dim <- dim(x) # for 0xN and Mx0 cases; needed in R (< 3.4.0)
if (!identical(dim(z), as.integer(dim))) dim(z) <- dim
if (isTRUE(useNames)) dimnames(z) <- dimnames(x)
if (useNames) dimnames(z) <- dimnames(x)
return(colAnys(z, na.rm = na.rm, dim. = dim., ..., useNames = useNames))
}
}
Expand Down
2 changes: 1 addition & 1 deletion R/rowQuantiles.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#' @param digits An \code{\link[base]{integer}} specifying the precision of
#' the formatted percentages. Not used when `useNames = FALSE`.
#' In **matrixStats** (< 0.63.0), the default used to be
#' `max(2L, getOption("digits"))` inline with R (< 4.1.0).
#' `max(2L, getOption("digits"))` in line with R (< 4.1.0).
#'
#' @param ... Additional arguments passed to \code{\link[stats]{quantile}}.
#'
Expand Down
50 changes: 22 additions & 28 deletions R/rowWeightedMeans.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,13 @@ rowWeightedMeans <- function(x, w = NULL, rows = NULL, cols = NULL,
res <- rep(NaN, times = m)

# Update names attribute?
if (!is.na(useNames)) {
if (useNames) {
names <- rownames(x)
if (!is.null(names)) {
names(res) <- names
}
} else {
names(res) <- NULL
if (useNames) {
names <- rownames(x)
if (!is.null(names)) {
names(res) <- names
}
} else {
names(res) <- NULL
}

return(res)
Expand Down Expand Up @@ -113,7 +111,7 @@ rowWeightedMeans <- function(x, w = NULL, rows = NULL, cols = NULL,
x <- W * x

# Preserve dimnames attribute?
if (!(is.na(useNames) || useNames)) {
if (!useNames) {
dimnames(x) <- NULL
}

Expand All @@ -132,14 +130,12 @@ rowWeightedMeans <- function(x, w = NULL, rows = NULL, cols = NULL,
x <- t_tx_OP_y(x, w, OP = "*", na.rm = FALSE)

# Update dimnames attribute?
if (!is.na(useNames)) {
if (useNames) {
if (!is.null(dimnames)) {
dimnames(x) <- dimnames
}
} else {
dimnames(x) <- NULL
if (useNames) {
if (!is.null(dimnames)) {
dimnames(x) <- dimnames
}
} else {
dimnames(x) <- NULL
}

w <- NULL # Not needed anymore
Expand All @@ -151,7 +147,7 @@ rowWeightedMeans <- function(x, w = NULL, rows = NULL, cols = NULL,
res <- rowMeans(x, na.rm = na.rm)

# Preserve names attribute?
if (!(is.na(useNames) || useNames)) {
if (!useNames) {
names(res) <- NULL
}
}
Expand Down Expand Up @@ -206,17 +202,15 @@ colWeightedMeans <- function(x, w = NULL, rows = NULL, cols = NULL,
res <- rep(NaN, times = m)

# Update names attribute?
if (!is.na(useNames)) {
if (useNames) {
names <- colnames(x)
if (!is.null(names)) {
names(res) <- names
}
} else {
names(res) <- NULL
if (useNames) {
names <- colnames(x)
if (!is.null(names)) {
names(res) <- names
}
}

} else {
names(res) <- NULL
}

return(res)
} else if (nw < n) {
w <- w[idxs]
Expand Down Expand Up @@ -271,7 +265,7 @@ colWeightedMeans <- function(x, w = NULL, rows = NULL, cols = NULL,
}

# Preserve names attribute?
if (!(is.na(useNames) || useNames)) {
if (!useNames) {
names(res) <- NULL
}

Expand Down
4 changes: 2 additions & 2 deletions R/rowWeightedMedians.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ rowWeightedMedians <- function(x, w = NULL, rows = NULL, cols = NULL,
})

# Preserve names attribute?
if (!(is.na(useNames) || useNames)) {
if (!useNames) {
names(res) <- NULL
}

Expand Down Expand Up @@ -125,7 +125,7 @@ colWeightedMedians <- function(x, w = NULL, rows = NULL, cols = NULL,
})

# Preserve names attribute?
if (!(is.na(useNames) || useNames)) {
if (!useNames) {
names(res) <- NULL
}

Expand Down
2 changes: 1 addition & 1 deletion man/rowQuantiles.Rd

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

0 comments on commit f658bb3

Please sign in to comment.