library_call_linter: Library call linter

View source: R/library_call_linter.R

library_call_linterR Documentation

Library call linter

Description

Force library calls to all be at the top of the script.

Usage

library_call_linter(allow_preamble = TRUE)

Arguments

allow_preamble

Logical, default TRUE. If FALSE, no code is allowed to precede the first library() call, otherwise some setup code is allowed, but all library() calls must follow consecutively after the first one.

Tags

best_practices, configurable, readability, style

See Also

linters for a complete list of linters available in lintr.

Examples

# will produce lints
lint(
  text = "
    library(dplyr)
    print('test')
    library(tidyr)
  ",
  linters = library_call_linter()
)

lint(
  text = "
    library(dplyr)
    print('test')
    library(tidyr)
    library(purrr)
  ",
  linters = library_call_linter()
)

# okay
lint(
  text = "
    library(dplyr)
    print('test')
  ",
  linters = library_call_linter()
)

lint(
  text = "
    # comment
    library(dplyr)
  ",
  linters = library_call_linter()
)


lintr documentation built on Nov. 7, 2023, 5:07 p.m.