---
title: "RStudio"
editor:
  markdown:
    wrap: sentence
    canonical: true
---

RStudio does not support the [Language Server Protocol](https://microsoft.github.io/language-server-protocol/), but you can still use Air as an *external formatter*.

# Installation

Ensure you have at least RStudio version 2024.12.0, which you can download from [here](https://posit.co/download/rstudio-desktop/).
Additionally, you'll need to install the Air [command line tool](cli.qmd).

Next, you'll need to tell RStudio to use Air as an external formatter:

-   Open `Tools -> Global Options -> Code`

-   Choose the `Formatting` tab at the top

-   Change the `Code formatter:` option to `External`

-   Change the `Reformat command:` to `{path/to/air} format`

    -   Note that you set this to a partially complete command!
        RStudio will append the name of the file to this partial command, but you *must* specify `format` in addition to the path to Air for it to work.

    -   The easiest way to figure out `{path/to/air}` for yourself is to run `which air` from a Terminal on Unix, and `where air` from the Command Prompt on Windows.
        Note that if your `{path/to/air}` contains any spaces, then you will need to wrap it in double quotes, like `"/Users/Your Name/air" format`.

-   Apply the changes and exit the settings.

At this point, explicit calls to `Reformat Selection` and `Reformat Document` should use Air.
If you'd also like RStudio to invoke Air on save, follow the instructions in [Format on Save](#rstudio-format-on-save).

![](./images/rstudio/external-formatter.png){fig-alt="Setting Air as an external formatter with Tools -> Global Options -> Code -> Formatting" fig-align="center"}

# Features

## Format on save {#rstudio-format-on-save}

After you've set Air as an external formatter, you can either tell RStudio to format all documents on save, or set this on a per document basis.

To format all documents on save, open `Tools -> Global Options -> Code -> Saving` and check `Reformat documents on save`.

![](images/rstudio/format-on-save.png){fig-alt="Setting RStudio to format all documents on save in Tools -> Global Options -> Code -> Saving" fig-align="center"}

To format individual documents on save, open the file specific settings and check `Reformat Document on Save`.

![](images/rstudio/reformat-document-on-save.png){fig-align="center"}

<!--# Come back and add video of formatting in action -->

## Quarto

There is currently no way to use Air in RStudio with Quarto documents.
