system.file()
has a ...
argument which, internally, is passed to
file.path()
, so including it in user code is repetitive.
See also
linters for a complete list of linters available in lintr.
Examples
# will produce lints
lint(
text = 'system.file(file.path("path", "to", "data"), package = "foo")',
linters = system_file_linter()
)
#> <text>:1:1: warning: [system_file_linter] Use the `...` argument of system.file() to expand paths, e.g. system.file("data", "model.csv", package = "myrf") instead of system.file(file.path("data", "model.csv"), package = "myrf")
#> system.file(file.path("path", "to", "data"), package = "foo")
#> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lint(
text = 'file.path(system.file(package = "foo"), "path", "to", "data")',
linters = system_file_linter()
)
#> <text>:1:1: warning: [system_file_linter] Use the `...` argument of system.file() to expand paths, e.g. system.file("data", "model.csv", package = "myrf") instead of file.path(system.file(package = "myrf"), "data", "model.csv")
#> file.path(system.file(package = "foo"), "path", "to", "data")
#> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# okay
lint(
text = 'system.file("path", "to", "data", package = "foo")',
linters = system_file_linter()
)
#> ℹ No lints found.