Skip to content

Commit

Permalink
STYLE: More lintr conformations
Browse files Browse the repository at this point in the history
  • Loading branch information
HenrikBengtsson committed Mar 29, 2017
1 parent 4f7e45a commit 7e3dfa2
Show file tree
Hide file tree
Showing 78 changed files with 656 additions and 337 deletions.
3 changes: 2 additions & 1 deletion R/benchmark.R
@@ -1,4 +1,5 @@
benchmark <- function(fcn, tags = NULL, path = NULL, workdir = "reports", envir = parent.frame(), ...) {
benchmark <- function(fcn, tags = NULL, path = NULL, workdir = "reports",
envir = parent.frame(), ...) {
requireNamespace("R.rsp") || stop("R.rsp not installed.")

if (is.function(fcn)) {
Expand Down
4 changes: 2 additions & 2 deletions R/binCounts.R
Expand Up @@ -12,9 +12,9 @@
#' @param idxs A \code{\link[base]{vector}} indicating subset of elements to
#' operate over. If \code{\link[base]{NULL}}, no subsetting is done.
#'
#' @param bx A \code{\link[base]{numeric}} \code{\link[base]{vector}} of B+1
#' @param bx A \code{\link[base]{numeric}} \code{\link[base]{vector}} of B + 1
#' ordered positions specifying the B > 0 bins \code{[bx[1], bx[2])},
#' \code{[bx[2], bx[3])}, ..., \code{[bx[B], bx[B+1])}.
#' \code{[bx[2], bx[3])}, ..., \code{[bx[B], bx[B + 1])}.
#'
#' @param right If \code{\link[base:logical]{TRUE}}, the bins are right-closed
#' (left open), otherwise left-closed (right open).
Expand Down
10 changes: 6 additions & 4 deletions R/binMeans.R
Expand Up @@ -14,9 +14,9 @@
#' @param idxs A \code{\link[base]{vector}} indicating subset of elements to
#' operate over. If \code{\link[base]{NULL}}, no subsetting is done.
#'
#' @param bx A \code{\link[base]{numeric}} \code{\link[base]{vector}} of B+1
#' @param bx A \code{\link[base]{numeric}} \code{\link[base]{vector}} of B + 1
#' ordered positions specifying the B > 0 bins \code{[bx[1], bx[2])},
#' \code{[bx[2], bx[3])}, ..., \code{[bx[B], bx[B+1])}.
#' \code{[bx[2], bx[3])}, ..., \code{[bx[B], bx[B + 1])}.
#'
#' @param na.rm If \code{\link[base:logical]{TRUE}}, missing values in \code{y}
#' are dropped before calculating the mean, otherwise not.
Expand Down Expand Up @@ -51,7 +51,8 @@
#'
#' @keywords univar
#' @export
binMeans <- function(y, x, idxs = NULL, bx, na.rm = TRUE, count = TRUE, right = FALSE, ...) {
binMeans <- function(y, x, idxs = NULL, bx, na.rm = TRUE, count = TRUE,
right = FALSE, ...) {
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Validate arguments
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand All @@ -69,7 +70,8 @@ binMeans <- function(y, x, idxs = NULL, bx, na.rm = TRUE, count = TRUE, right =
stop("Argument 'x' is not numeric: ", mode(x))
}
if (length(x) != n) {
stop("Argument 'y' and 'x' are of different lengths: ", length(y), " != ", length(x))
stop("Argument 'y' and 'x' are of different lengths: ",
length(y), " != ", length(x))
}

# Argument 'bx':
Expand Down
6 changes: 4 additions & 2 deletions R/rowAvgsPerColSet.R
Expand Up @@ -45,7 +45,8 @@
#' @author Henrik Bengtsson
#' @keywords internal utilities
#' @export
rowAvgsPerColSet <- function(X, W = NULL, rows = NULL, S, FUN = rowMeans, ..., tFUN = FALSE) {
rowAvgsPerColSet <- function(X, W = NULL, rows = NULL, S,
FUN = rowMeans, ..., tFUN = FALSE) {
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Validate arguments
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down Expand Up @@ -138,7 +139,8 @@ rowAvgsPerColSet <- function(X, W = NULL, rows = NULL, S, FUN = rowMeans, ..., t

#' @rdname rowAvgsPerColSet
#' @export
colAvgsPerRowSet <- function(X, W = NULL, cols = NULL, S, FUN = colMeans, tFUN = FALSE, ...) {
colAvgsPerRowSet <- function(X, W = NULL, cols = NULL, S,
FUN = colMeans, tFUN = FALSE, ...) {
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Validate arguments
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down
4 changes: 2 additions & 2 deletions R/rowCollapse.R
Expand Up @@ -41,7 +41,7 @@ rowCollapse <- function(x, idxs, rows = NULL, dim. = dim(x), ...) {
idxs <- rep(idxs, length.out = dim.[1L])

# Columns of interest
cols <- 0:(dim.[2L]-1L)
cols <- 0:(dim.[2L] - 1L)
cols <- cols[idxs]

# Calculate column-based indices
Expand Down Expand Up @@ -70,7 +70,7 @@ colCollapse <- function(x, idxs, cols = NULL, dim. = dim(x), ...) {
rows <- rows[idxs]

# Calculate column-based indices
idxs <- dim.[1L] * 0:(dim.[2L]-1L) + rows
idxs <- dim.[1L] * 0:(dim.[2L] - 1L) + rows
rows <- NULL # Not needed anymore

x[idxs]
Expand Down
28 changes: 19 additions & 9 deletions R/rowCounts.R
Expand Up @@ -9,7 +9,7 @@
#' temporarily create/allocate a matrix, if only such is needed only for these
#' calculations.
#'
#' @param x An NxK \code{\link[base]{matrix}} or an N*K
#' @param x An NxK \code{\link[base]{matrix}} or an N * K
#' \code{\link[base]{vector}}.
#'
#' @param idxs,rows,cols A \code{\link[base]{vector}} indicating subset of
Expand Down Expand Up @@ -37,7 +37,8 @@
#' @author Henrik Bengtsson
#' @keywords array logic iteration univar
#' @export
rowCounts <- function(x, rows = NULL, cols = NULL, value = TRUE, na.rm = FALSE, dim. = dim(x), ...) {
rowCounts <- function(x, rows = NULL, cols = NULL, value = TRUE,
na.rm = FALSE, dim. = dim(x), ...) {
# Argument 'x':
if (is.matrix(x)) {
} else if (is.vector(x)) {
Expand Down Expand Up @@ -85,7 +86,8 @@ rowCounts <- function(x, rows = NULL, cols = NULL, value = TRUE, na.rm = FALSE,

#' @rdname rowCounts
#' @export
colCounts <- function(x, rows = NULL, cols = NULL, value = TRUE, na.rm = FALSE, dim. = dim(x), ...) {
colCounts <- function(x, rows = NULL, cols = NULL, value = TRUE,
na.rm = FALSE, dim. = dim(x), ...) {
# Argument 'x':
if (is.matrix(x)) {
} else if (is.vector(x)) {
Expand Down Expand Up @@ -121,9 +123,13 @@ colCounts <- function(x, rows = NULL, cols = NULL, value = TRUE, na.rm = FALSE,
dim. <- dim(x)

if (is.na(value)) {
counts <- apply(x, MARGIN = 2L, FUN = function(x) sum(is.na(x)))
counts <- apply(x, MARGIN = 2L, FUN = function(x)
sum(is.na(x))
)
} else {
counts <- apply(x, MARGIN = 2L, FUN = function(x) sum(x == value, na.rm = na.rm))
counts <- apply(x, MARGIN = 2L, FUN = function(x)
sum(x == value, na.rm = na.rm)
)
}
}

Expand Down Expand Up @@ -171,7 +177,8 @@ count <- function(x, idxs = NULL, value = TRUE, na.rm = FALSE, ...) {

#' @rdname rowCounts
#' @export
rowAlls <- function(x, rows = NULL, cols = NULL, value = TRUE, na.rm = FALSE, dim. = dim(x), ...) {
rowAlls <- function(x, rows = NULL, cols = NULL, value = TRUE,
na.rm = FALSE, dim. = dim(x), ...) {
if (is.numeric(x) || is.logical(x)) {
na.rm <- as.logical(na.rm)
hasNAs <- TRUE
Expand All @@ -197,7 +204,8 @@ rowAlls <- function(x, rows = NULL, cols = NULL, value = TRUE, na.rm = FALSE, di

#' @rdname rowCounts
#' @export
colAlls <- function(x, rows = NULL, cols = NULL, value = TRUE, na.rm = FALSE, dim. = dim(x), ...) {
colAlls <- function(x, rows = NULL, cols = NULL, value = TRUE,
na.rm = FALSE, dim. = dim(x), ...) {
if (is.numeric(x) || is.logical(x)) {
na.rm <- as.logical(na.rm)
hasNAs <- TRUE
Expand Down Expand Up @@ -244,7 +252,8 @@ allValue <- function(x, idxs = NULL, value = TRUE, na.rm = FALSE, ...) {

#' @rdname rowCounts
#' @export
rowAnys <- function(x, rows = NULL, cols = NULL, value = TRUE, na.rm = FALSE, dim. = dim(x), ...) {
rowAnys <- function(x, rows = NULL, cols = NULL, value = TRUE,
na.rm = FALSE, dim. = dim(x), ...) {
if (is.numeric(x) || is.logical(x)) {
na.rm <- as.logical(na.rm)
hasNAs <- TRUE
Expand All @@ -270,7 +279,8 @@ rowAnys <- function(x, rows = NULL, cols = NULL, value = TRUE, na.rm = FALSE, di

#' @rdname rowCounts
#' @export
colAnys <- function(x, rows = NULL, cols = NULL, value = TRUE, na.rm = FALSE, dim. = dim(x), ...) {
colAnys <- function(x, rows = NULL, cols = NULL, value = TRUE,
na.rm = FALSE, dim. = dim(x), ...) {
if (is.numeric(x) || is.logical(x)) {
na.rm <- as.logical(na.rm)
hasNAs <- TRUE
Expand Down
12 changes: 8 additions & 4 deletions R/rowDiffs.R
Expand Up @@ -26,12 +26,16 @@
#' @seealso See also \code{\link{diff2}}().
#' @keywords array iteration robust univar
#' @export
rowDiffs <- function(x, rows = NULL, cols = NULL, lag = 1L, differences = 1L, ...) {
.Call(C_rowDiffs, x, dim(x), rows, cols, as.integer(lag), as.integer(differences), TRUE)
rowDiffs <- function(x, rows = NULL, cols = NULL,
lag = 1L, differences = 1L, ...) {
.Call(C_rowDiffs, x, dim(x), rows, cols,
as.integer(lag), as.integer(differences), TRUE)
}

#' @rdname rowDiffs
#' @export
colDiffs <- function(x, rows = NULL, cols = NULL, lag = 1L, differences = 1L, ...) {
.Call(C_rowDiffs, x, dim(x), rows, cols, as.integer(lag), as.integer(differences), FALSE)
colDiffs <- function(x, rows = NULL, cols = NULL,
lag = 1L, differences = 1L, ...) {
.Call(C_rowDiffs, x, dim(x), rows, cols,
as.integer(lag), as.integer(differences), FALSE)
}
6 changes: 4 additions & 2 deletions R/rowIQRs.R
Expand Up @@ -32,7 +32,8 @@
#' @importFrom stats quantile
#' @export
rowIQRs <- function(x, rows = NULL, cols = NULL, na.rm = FALSE, ...) {
Q <- rowQuantiles(x, rows = rows, cols = cols, probs = c(0.25, 0.75), na.rm = na.rm, drop = FALSE, ...)
Q <- rowQuantiles(x, rows = rows, cols = cols,
probs = c(0.25, 0.75), na.rm = na.rm, drop = FALSE, ...)
ans <- Q[, 2L, drop = TRUE] - Q[, 1L, drop = TRUE]

# Remove attributes
Expand All @@ -44,7 +45,8 @@ rowIQRs <- function(x, rows = NULL, cols = NULL, na.rm = FALSE, ...) {
#' @rdname rowIQRs
#' @export
colIQRs <- function(x, rows = NULL, cols = NULL, na.rm = FALSE, ...) {
Q <- colQuantiles(x, rows = rows, cols = cols, probs = c(0.25, 0.75), na.rm = na.rm, drop = FALSE, ...)
Q <- colQuantiles(x, rows = rows, cols = cols,
probs = c(0.25, 0.75), na.rm = na.rm, drop = FALSE, ...)
ans <- Q[, 2L, drop = TRUE] - Q[, 1L, drop = TRUE]

# Remove attributes
Expand Down
6 changes: 4 additions & 2 deletions R/rowLogSumExps.R
Expand Up @@ -35,7 +35,8 @@
#'
#' @keywords array
#' @export
rowLogSumExps <- function(lx, rows = NULL, cols = NULL, na.rm = FALSE, dim. = dim(lx), ...) {
rowLogSumExps <- function(lx, rows = NULL, cols = NULL, na.rm = FALSE,
dim. = dim(lx), ...) {
dim. <- as.integer(dim.)
hasNA <- TRUE
res <- .Call(C_rowLogSumExps,
Expand All @@ -54,7 +55,8 @@ rowLogSumExps <- function(lx, rows = NULL, cols = NULL, na.rm = FALSE, dim. = di

#' @rdname rowLogSumExps
#' @export
colLogSumExps <- function(lx, rows = NULL, cols = NULL, na.rm = FALSE, dim. = dim(lx), ...) {
colLogSumExps <- function(lx, rows = NULL, cols = NULL, na.rm = FALSE,
dim. = dim(lx), ...) {
dim. <- as.integer(dim.)
hasNA <- TRUE
res <- .Call(C_rowLogSumExps,
Expand Down
16 changes: 10 additions & 6 deletions R/rowMads.R
@@ -1,12 +1,14 @@
#' @rdname rowSds
#' @export
rowMads <- function(x, rows = NULL, cols = NULL, center = NULL, constant = 1.4826, na.rm = FALSE, dim. = dim(x), centers = NULL, ...) {
rowMads <- function(x, rows = NULL, cols = NULL, center = NULL,
constant = 1.4826, na.rm = FALSE,
dim. = dim(x), centers = NULL, ...) {
## BACKWARD COMPATIBILITY:
## - Added to matrixStats 0.14.0.
## - Defunct in matrixStats (>= 0.15.0)
if (!is.null(centers)) {
center <- centers
.Defunct(msg = "Argument 'centers' for matrixStats::rowMads() has been renamed to 'center'. Please update code accordingly.")
.Defunct(msg = "Argument 'centers' for matrixStats::rowMads() has been renamed to 'center'. Please update code accordingly.") #nolint
}

if (is.null(center)) {
Expand All @@ -30,21 +32,23 @@ rowMads <- function(x, rows = NULL, cols = NULL, center = NULL, constant = 1.482
if (is.null(dim(x))) dim(x) <- dim. # prevent from dim dropping
x <- abs(x)
x <- rowMedians(x, na.rm = na.rm, ...)
x <- constant*x
x <- constant * x
}
x
}


#' @rdname rowSds
#' @export
colMads <- function(x, rows = NULL, cols = NULL, center = NULL, constant = 1.4826, na.rm = FALSE, dim. = dim(x), centers = NULL, ...) {
colMads <- function(x, rows = NULL, cols = NULL, center = NULL,
constant = 1.4826, na.rm = FALSE,
dim. = dim(x), centers = NULL, ...) {
## BACKWARD COMPATIBILITY:
## - Added to matrixStats 0.14.0.
## - Defunct in matrixStats (>= 0.15.0)
if (!is.null(centers)) {
center <- centers
.Defunct(msg = "Argument 'centers' for matrixStats::colMads() has been renamed to 'center'. Please update code accordingly.")
.Defunct(msg = "Argument 'centers' for matrixStats::colMads() has been renamed to 'center'. Please update code accordingly.") #nolint
}

if (is.null(center)) {
Expand Down Expand Up @@ -72,7 +76,7 @@ colMads <- function(x, rows = NULL, cols = NULL, center = NULL, constant = 1.482
x <- t_tx_OP_y(x, center, OP = "-", na.rm = FALSE)
x <- abs(x)
x <- colMedians(x, na.rm = na.rm, ...)
x <- constant*x
x <- constant * x
}
x
}
6 changes: 4 additions & 2 deletions R/rowMedians.R
Expand Up @@ -37,7 +37,8 @@
#'
#' @keywords array iteration robust univar
#' @export
rowMedians <- function(x, rows = NULL, cols = NULL, na.rm = FALSE, dim. = dim(x), ...) {
rowMedians <- function(x, rows = NULL, cols = NULL, na.rm = FALSE,
dim. = dim(x), ...) {
dim. <- as.integer(dim.)
na.rm <- as.logical(na.rm)
hasNAs <- TRUE # Add as an argument? /2007-08-24
Expand All @@ -46,7 +47,8 @@ rowMedians <- function(x, rows = NULL, cols = NULL, na.rm = FALSE, dim. = dim(x)

#' @rdname rowMedians
#' @export
colMedians <- function(x, rows = NULL, cols = NULL, na.rm = FALSE, dim. = dim(x), ...) {
colMedians <- function(x, rows = NULL, cols = NULL, na.rm = FALSE,
dim. = dim(x), ...) {
dim. <- as.integer(dim.)
na.rm <- as.logical(na.rm)
hasNAs <- TRUE # Add as an argument? /2007-08-24
Expand Down
6 changes: 4 additions & 2 deletions R/rowOrderStats.R
Expand Up @@ -37,7 +37,8 @@
#'
#' @keywords array iteration robust univar
#' @export
rowOrderStats <- function(x, rows = NULL, cols = NULL, which, dim. = dim(x), ...) {
rowOrderStats <- function(x, rows = NULL, cols = NULL, which,
dim. = dim(x), ...) {
dim. <- as.integer(dim.)

# Check missing values
Expand All @@ -52,7 +53,8 @@ rowOrderStats <- function(x, rows = NULL, cols = NULL, which, dim. = dim(x), ...

#' @rdname rowOrderStats
#' @export
colOrderStats <- function(x, rows = NULL, cols = NULL, which, dim. = dim(x), ...) {
colOrderStats <- function(x, rows = NULL, cols = NULL, which,
dim. = dim(x), ...) {
dim. <- as.integer(dim.)

# Check missing values
Expand Down
6 changes: 4 additions & 2 deletions R/rowProds.R
Expand Up @@ -37,7 +37,8 @@
#'
#' @keywords array iteration robust univar
#' @export
rowProds <- function(x, rows = NULL, cols = NULL, na.rm = FALSE, method = c("direct", "expSumLog"), ...) {
rowProds <- function(x, rows = NULL, cols = NULL, na.rm = FALSE,
method = c("direct", "expSumLog"), ...) {
# Apply subset
if (!is.null(rows) && !is.null(cols)) x <- x[rows, cols, drop = FALSE]
else if (!is.null(rows)) x <- x[rows, , drop = FALSE]
Expand Down Expand Up @@ -71,7 +72,8 @@ rowProds <- function(x, rows = NULL, cols = NULL, na.rm = FALSE, method = c("dir

#' @rdname rowProds
#' @export
colProds <- function(x, rows = NULL, cols = NULL, na.rm = FALSE, method = c("direct", "expSumLog"), ...) {
colProds <- function(x, rows = NULL, cols = NULL, na.rm = FALSE,
method = c("direct", "expSumLog"), ...) {
# Apply subset
if (!is.null(rows) && !is.null(cols)) x <- x[rows, cols, drop = FALSE]
else if (!is.null(rows)) x <- x[rows, , drop = FALSE]
Expand Down

0 comments on commit 7e3dfa2

Please sign in to comment.