r.md

  1# R
  2
  3R support is available via multiple R Zed extensions:
  4
  5- [ocsmit/zed-r](https://github.com/ocsmit/zed-r)
  6
  7  - Tree-sitter: [r-lib/tree-sitter-r](https://github.com/r-lib/tree-sitter-r)
  8  - Language-Server: [REditorSupport/languageserver](https://github.com/REditorSupport/languageserver)
  9
 10- [posit-dev/air](https://github.com/posit-dev/air/tree/main/editors/zed)
 11  - Language-Server: [posit-dev/air](https://github.com/posit-dev/air)
 12
 13## Installation
 14
 151. [Download and Install R](https://cloud.r-project.org/).
 162. Install the R packages `languageserver` and `lintr`:
 17
 18```R
 19install.packages("languageserver")
 20install.packages("lintr")
 21```
 22
 233. Install the [ocsmit/zed-r](https://github.com/ocsmit/zed-r) through Zed's extensions manager.
 24
 25For example on macOS:
 26
 27```sh
 28brew install --cask r
 29Rscript --version
 30Rscript -e 'options(repos = "https://cran.rstudio.com/"); install.packages("languageserver")'
 31Rscript -e 'options(repos = "https://cran.rstudio.com/"); install.packages("lintr")'
 32Rscript -e 'packageVersion("languageserver")'
 33Rscript -e 'packageVersion("lintr")'
 34```
 35
 36## Configuration
 37
 38### Linting
 39
 40`REditorSupport/languageserver` bundles support for [r-lib/lintr](https://github.com/r-lib/lintr) as a linter. This can be configured via the use of a `.lintr` inside your project (or in your home directory for global defaults).
 41
 42```r
 43linters: linters_with_defaults(
 44    line_length_linter(120),
 45    commented_code_linter = NULL
 46  )
 47exclusions: list(
 48    "inst/doc/creating_linters.R" = 1,
 49    "inst/example/bad.R",
 50    "tests/testthat/exclusions-test"
 51  )
 52```
 53
 54Or exclude it from linting anything,
 55
 56```r
 57exclusions: list(".")
 58```
 59
 60See [Using lintr](https://lintr.r-lib.org/articles/lintr.html) for a complete list of options,
 61
 62### Formatting
 63
 64`REditorSupport/languageserver` bundles support for [r-lib/styler](https://github.com/r-lib/styler) as a formatter. See [Customizing Styler](https://cran.r-project.org/web/packages/styler/vignettes/customizing_styler.html) for more information on how to customize its behavior.
 65
 66<!--
 67TBD: Get this working
 68
 69### REditorSupport/languageserver Configuration
 70
 71You can configure the [R languageserver settings](https://github.com/REditorSupport/languageserver#settings) via Zed Project Settings `.zed/settings.json` or Zed User Settings `~/.config/zed/settings.json`:
 72
 73For example to disable Lintr linting and suppress code snippet suggestions (both enabled by default):
 74
 75```json [settings]
 76{
 77  "lsp": {
 78    "r_language_server": {
 79      "settings": {
 80        "r": {
 81          "lsp": {
 82            "diagnostics": false,
 83            "snippet_support": false
 84          }
 85        }
 86      }
 87    }
 88  }
 89}
 90```
 91
 92-->
 93
 94<!--
 95TBD: R REPL Docs
 96
 97## REPL
 98
 99### Ark Installation
100
101To use the Zed REPL with R you need to install [Ark](https://github.com/posit-dev/ark), an R Kernel for Jupyter applications.
102You can down the latest version from the [Ark GitHub Releases](https://github.com/posit-dev/ark/releases) and then extract the `ark` binary to a directory in your `PATH`.
103
104For example to install the latest non-debug build:
105
106```sh
107# macOS
108cd /tmp
109curl -L -o ark-latest-darwin.zip \
110    $(curl -s "https://api.github.com/repos/posit-dev/ark/releases/latest" | \
111    jq -r '.assets[] | select(.name | contains("darwin-universal") and (contains("debug") | not)) | .browser_download_url')
112unzip ark-latest-darwin.zip ark
113sudo mv /tmp/ark /usr/local/bin/
114```
115
116```sh
117# Linux X86_64
118cd /tmp
119curl -L -o ark-latest-linux.zip \
120    $(curl -s "https://api.github.com/repos/posit-dev/ark/releases/latest" \
121        | jq -r '.assets[] | select(.name | contains("linux-x64") and (contains("debug") | not)) | .browser_download_url'
122    )
123unzip ark-latest-linux.zip ark
124sudo mv /tmp/ark /usr/local/bin/
125```
126
127-->