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### REditorSupport/languageserver Configuration
67
68You 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`:
69
70For example to disable Lintr linting and suppress code snippet suggestions (both enabled by default):
71
72```json
73{
74 "lsp": {
75 "r_language_server": {
76 "settings": {
77 "r": {
78 "lsp": {
79 "diagnostics": false,
80 "snippet_support": false
81 }
82 }
83 }
84 }
85 }
86}
87```
88
89<!--
90TBD: R REPL Docs
91
92## REPL
93
94### Ark Installation
95
96To use the Zed REPL with R you need to install [Ark](https://github.com/posit-dev/ark), an R Kernel for Jupyter applications.
97You 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`.
98
99For example to install the latest non-debug build:
100
101```sh
102# macOS
103cd /tmp
104curl -L -o ark-latest-darwin.zip \
105 $(curl -s "https://api.github.com/repos/posit-dev/ark/releases/latest" | \
106 jq -r '.assets[] | select(.name | contains("darwin-universal") and (contains("debug") | not)) | .browser_download_url')
107unzip ark-latest-darwin.zip ark
108sudo mv /tmp/ark /usr/local/bin/
109```
110
111```sh
112# Linux X86_64
113cd /tmp
114curl -L -o ark-latest-linux.zip \
115 $(curl -s "https://api.github.com/repos/posit-dev/ark/releases/latest" \
116 | jq -r '.assets[] | select(.name | contains("linux-x64") and (contains("debug") | not)) | .browser_download_url'
117 )
118unzip ark-latest-linux.zip ark
119sudo mv /tmp/ark /usr/local/bin/
120```
121
122-->