Learn R Programming

lintr (version 3.1.2)

library_call_linter: 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

Run this code
# 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()
)

Run the code above in your browser using DataLab