tests/testthat/test-system_file_linter.R

test_that("system_file_linter skips allowed usages", {
  expect_lint("system.file('a', 'b', 'c')", NULL, system_file_linter())
  expect_lint("file.path('a', 'b', 'c')", NULL, system_file_linter())
})

test_that("system_file_linter blocks simple disallowed usages", {
  expect_lint(
    "system.file(file.path('path', 'to', 'data'), package = 'foo')",
    rex::rex("Use the `...` argument of system.file() to expand paths"),
    system_file_linter()
  )

  expect_lint(
    "file.path(system.file(package = 'foo'), 'path', 'to', 'data')",
    rex::rex("Use the `...` argument of system.file() to expand paths"),
    system_file_linter()
  )
})

Try the lintr package in your browser

Any scripts or data that you put into this service are public.

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