sample_int_linter: Require usage of sample.int(n, m, ...) over sample(1:n, m,...

View source: R/sample_int_linter.R

sample_int_linterR Documentation

Require usage of sample.int(n, m, ...) over sample(1:n, m, ...)

Description

sample.int() is preferable to sample() for the case of sampling numbers between 1 and n. sample calls sample.int() "under the hood".

Usage

sample_int_linter()

Tags

efficiency, readability, robustness

See Also

linters for a complete list of linters available in lintr.

Examples

# will produce lints
lint(
  text = "sample(1:10, 2)",
  linters = sample_int_linter()
)

lint(
  text = "sample(seq(4), 2)",
  linters = sample_int_linter()
)

lint(
  text = "sample(seq_len(8), 2)",
  linters = sample_int_linter()
)

# okay
lint(
  text = "sample(seq(1, 5, by = 2), 2)",
  linters = sample_int_linter()
)

lint(
  text = "sample(letters, 2)",
  linters = sample_int_linter()
)


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