matrix_apply_linter: Require usage of 'colSums(x)' or 'rowSums(x)' over 'apply(x,...

View source: R/matrix_apply_linter.R

matrix_apply_linterR Documentation

Require usage of colSums(x) or rowSums(x) over apply(x, ., sum)

Description

colSums() and rowSums() are clearer and more performant alternatives to apply(x, 2, sum) and apply(x, 1, sum) respectively in the case of 2D arrays, or matrices

Usage

matrix_apply_linter()

Tags

efficiency, readability

See Also

linters for a complete list of linters available in lintr.

Examples

# will produce lints
lint(
  text = "apply(x, 1, sum)",
  linters = matrix_apply_linter()
)

lint(
  text = "apply(x, 2, sum)",
  linters = matrix_apply_linter()
)

lint(
  text = "apply(x, 2, sum, na.rm = TRUE)",
  linters = matrix_apply_linter()
)

lint(
  text = "apply(x, 2:4, sum)",
  linters = matrix_apply_linter()
)


jimhester/lintr documentation built on April 24, 2024, 8:21 a.m.