Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
q050cr opened this issue Dec 8, 2024 · 0 comments
Open

Comments

@q050cr
Copy link

q050cr commented Dec 8, 2024

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?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant