Skip to content
Grant McDermott edited this page Feb 19, 2025 · 5 revisions

R code linting (diagnostics) is provided by lintr via language server and is enabled by default. It provides syntax error warnings as well as style guidelines.

To disable diagnostics, you might add the following to the VS Code settings:

{
  "r.lsp.diagnostics": false
}

However, you will not be notified if syntax errors in the code are detected.

To customize the linting behavior, edit the global lintr config file at ~/.lintr, or project-specific lintr config file at ${workspaceFolder}/.lintr.

  • Visit Individual linters for a complete list of supported linters.
  • Visit the Configuring linters for a complete guide to customizing lintr config regarding the list of linters and file or line exclusions.

Examples

Only detect syntax errors:

linters: list()

Deviate from default linters:

Adjust the number of characters in each line for line_length_linter and disable commented_code_linter.

linters: linters_with_defaults(
    line_length_linter(120), 
    commented_code_linter = NULL
  )

A more aggressive example, turning off the <- assignment linter (i.e., = is fine) among other things. Background here.

linters: linters_with_defaults(
   line_length_linter    = NULL, # note: vscode-R default is 120
   cyclocomp_linter      = NULL, # same as vscode-R
   object_name_linter    = NULL, # same as vscode-R
   object_usage_linter   = NULL, # same as vscode-R
   commented_code_linter = NULL,
   assignment_linter     = NULL,
   single_quotes_linter  = NULL,
   semicolon_linter      = NULL,
   seq_linter            = NULL,
   indentation_linter 	 = NULL
)

Only use specified linters:

linters: list(
  commas_linter(),
  duplicate_argument_linter(),
  missing_argument_linter(),
  missing_package_linter(),
  namespace_linter())
Clone this wiki locally