Skip to contents

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()

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()
)
#> <text>:1:1: warning: [sample_int_linter] sample.int(n, m, ...) is preferable to sample(1:n, m, ...).
#> sample(1:10, 2)
#> ^~~~~~~~~~~~~~~

lint(
  text = "sample(seq(4), 2)",
  linters = sample_int_linter()
)
#> <text>:1:1: warning: [sample_int_linter] sample.int(n, m, ...) is preferable to sample(seq(n), m, ...).
#> sample(seq(4), 2)
#> ^~~~~~~~~~~~~~~~~

lint(
  text = "sample(seq_len(8), 2)",
  linters = sample_int_linter()
)
#> <text>:1:1: warning: [sample_int_linter] sample.int(n, m, ...) is preferable to sample(seq_len(n), m, ...).
#> sample(seq_len(8), 2)
#> ^~~~~~~~~~~~~~~~~~~~~

# okay
lint(
  text = "sample(seq(1, 5, by = 2), 2)",
  linters = sample_int_linter()
)
#>  No lints found.

lint(
  text = "sample(letters, 2)",
  linters = sample_int_linter()
)
#>  No lints found.