quarto-dev / quarto-dev/quarto

Indentation issues for operators (%>% and +) in Quarto R chunks in VS Code

Open
#619 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
645
Forks
62
Avg merge
17h 42m
Merged PRs (30d)
13

Description

I’m experiencing issues with code indentation in Quarto R chunks while editing in VS Code, but everything works fine in plain R files. Specifically, when using operators like the pipe (%>%) or + (in ggplot2), the code does not indent correctly after I type them. However, the formatting is applied when I save the document, which interrupts the editing flow.

In plain R files, the indentation works as expected immediately after inserting these operators, but this behavior is inconsistent in Quarto documents.

Environment

  • OS: macOS 15.0.1
  • Quarto Version: 1.6.37
  • VS Code Version: 1.95.3

Steps to Reproduce

Open the following Quarto file in VS Code:

---
title: "R Code Indentation"
date: 2024-11-24
---

```{r}
#| label: ggplot

library(dplyr)
library(ggplot2)

ggplot(diamonds, aes(x = carat, y = price)) +
geom_point()  # Indentation issue with `+`
```

```{r}
#| label: pipe

diamonds %>%
select(1:3)  # Indentation issue with `%>%`
```
VS Code Settings

My settings.json in VS Code looks like below:

{
  "editor.formatOnSave": true,
  "editor.formatOnPaste": true,
  "editor.formatOnType": true,
  "editor.quickSuggestions": {
    "other": "on",
    "comments": "on",
    "strings": "on"
  },
  "editor.suggest.showSnippets": true,
  "editor.suggest.localityBonus": true,
  "r.rterm.mac": "path_to_my_radian/bin/radian",
  "r.bracketedPaste": true,
  "r.removeLeadingComments": true,
  "r.plot.useHttpgd": true,
  "[quarto]": {
    "editor.defaultFormatter": "quarto.quarto",
    // "editor.defaultFormatter": "REditorSupport.r", // also tried that...
    "editor.wordWrap": "wordWrapColumn",
    "editor.snippetSuggestions": "top"
  },
  "[r]": {
    "editor.defaultFormatter": "REditorSupport.r",
    "editor.wordWrap": "wordWrapColumn",
    "editor.snippetSuggestions": "top"
  },
  "[rmd]": {
    "editor.defaultFormatter": "REditorSupport.r",
    "editor.wordWrap": "wordWrapColumn",
    "editor.snippetSuggestions": "top"
  },
  "[yaml]": {
    "editor.defaultFormatter": "quarto.quarto"
  }
}

What I Have Tried:

  • Adjusting editor.formatOnSave and editor.formatOnType in my VS Code settings.
  • Ensuring that the R Language Server (languageserver) is running.
  • Changing settings for [quarto] and [r] in my settings.json file.

Despite these efforts, indentation for the Quarto R chunks does not work as intended while editing. It only takes effect on save.

Expected Behavior:
  • Indentation should work immediately after inserting a pipe in Quarto R chunks, similar to how it works in plain R files.
Any Suggestions?
  • Is there a specific configuration I’m missing for Quarto or VS Code to achieve consistent behavior?
  • Could this be a limitation of the R Language Server in Quarto documents?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the supplied Quarto document in VS Code with the listed formatting settings, then compare indentation after %>% and + with a plain R file. Trace the Quarto R-chunk handling and R language-server integration; done means operators trigger the expected indentation while typing, not only after saving.

Written by the indexing model from the issue text.

Assessment

Tech stack
r, vscode
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.