Skip to content

R Dev Guide: Document VS Code and Positron settings for working on R sources #105

@hturner

Description

@hturner

As discussed in #104, an.editorconfig that sets appropriate settings in other IDEs will result in incorrect indentation for C files with VS Code or Positron. So for the moment, I think it is best to advise people to use the IDE settings, rather than an .editorconfig.

We can add this in a new "IDE Setup" chapter of the R Dev Guide. I have partial settings below, we can compare this to the .editorconfig in #104 to develop more complete settings.

Note that using either the .editorconfig or the settings would be fine if you never work with C files. If an .editorconfig gets added to the R sources, we may want to add a note saying how to ignore it (if EditorConfig for VS Code extension installed, can disable for the current workspace via the Extensions panel).

VS Code

Here the settings for C and R files are the same. Ideally C would be different: every 8 spaces in an indent would be replaced by a tab (https://bugs.r-project.org/show_bug.cgi?id=18757#c1). I could not find a VS Code extension that does this - maybe we could write one??

{
  // Editor settings for C files
  // Cannot set to auto replace 8 spaces with tab (https://github.com/Microsoft/vscode/issues/ #42740, #5394)
  "[c]": {
    "editor.indentSize": 4, // indent 4 spaces each indent level
    "editor.tabSize": 8, // display 8 spaces as a tab
    "editor.insertSpaces": true, // need this to get indent size 4, else uses tabs to indent
    "editor.detectIndentation": false, // if set true, detects settings as above from the code in the file
  },
  // Editor settings for R files
  "[r]": {
    "editor.indentSize": 4,
    "editor.tabSize": 8,
    "editor.insertSpaces": true,
    "editor.detectIndentation": false
  },
  // Turn off linting for R files 
  "r.lsp.diagnostics": false
}

Positron

Same as VS Code but don't need r.lsp.diagnostics": false as not using R language server.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues in the documentation

    Type

    No type

    Projects

    Status

    To Do

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions