R
R language support.
How to install
With Forge Super installed, the button above opens the app on this extension, where you press Install. Nothing is installed until you do.
You can also open the Extensions panel in the app and search for R. The extension's id is r.
Don't have Forge Super yet? Download it here.
README
From the extension's repository, written by its authors and not by Mentenaz. See the source.
zed-r
Provides tree-sitter queries and Language Server Protocol (LSP) support for Zed.
Installing
The latest version can be installed from the Zed extensions menu, or by cloning the repo and installing it locally from the Zed extensions menu.
Additionally, it is recommended to run R code using Zed's REPL feature. To enable this, install either the Ark or Xeus Jupyter kernels; then in an R file create a REPL cell by typing # %% (or by using the shortcut available below) and run it by pressing ctrl-shift-enter.
Further information can be found at:
Note: Recently, there is an issue with ark not working with the REPL feature. You might want to test out the other kernel options.
LSP
The R packages languageserver and lintr are needed.
RStudio keybindings
- Add this to your keymap.json by opening the command palette (Ctrl+Shift+P) and selecting
zed: open keymap.
Note: macOS users will likely want to replace ctrl with cmd.
{
"context": "Editor",
"bindings": {
"ctrl-shift-f10": "repl::Restart", // Equivalent to restarting R in RStudio
"ctrl-\\": "assistant::InlineAssist",
"ctrl-shift-m": ["workspace::SendKeystrokes", "space |> space"],
"alt--": ["workspace::SendKeystrokes", "space < - space"],
"ctrl-alt-i": ["workspace::SendKeystrokes", "\n# space %%\n"],
"ctrl-shift-d": [
"task::Spawn",
{ "task_name": "Document local R package", "reveal_target": "center" }
],
"ctrl-alt-enter": [
"workspace::SendKeystrokes",
"ctrl-c ctrl-` ctrl-shift-v enter ctrl-`"
]
}
},
{
"context": "Workspace",
"bindings": {
"ctrl-shift-t": [
"task::Spawn",
{ "task_name": "Run all R tests", "reveal_target": "center" }
],
"ctrl-shift-r": [
"task::Spawn",
{ "task_name": "Run current R file test", "reveal_target": "center" }
],
"ctrl-shift-b": [
"task::Spawn",
{ "task_name": "Install local R package", "reveal_target": "center" }
],
"ctrl-2": [
"task::Spawn",
{ "task_name": "R Terminal", "reveal_target": "dock" }
],
"ctrl-shift-s": [
"task::Spawn",
{ "task_name": "Source current file", "reveal_target": "center"}
],
"ctrl-shift-e": [
"task::Spawn",
{ "task_name": "Check local R package", "reveal_target": "center"}
]
}
}
Tasks for R (works with RStudio keybindings)
- Add this to your tasks.json by opening the command palette (Ctrl+Shift+P) and selecting
zed: open tasks
[
{
"label": "R Terminal",
"command": "R", // You could also use [radian](https://github.com/randy3k/radian)
"cwd": "$ZED_WORKTREE_ROOT",
"use_new_terminal": true
},
{
"label": "Install local R package",
"command": "R CMD INSTALL .",
"cwd": "$ZED_WORKTREE_ROOT",
"use_new_terminal": false,
"allow_concurrent_runs": false,
"reveal": "always",
"show_summary": true,
"show_output": true,
"show_error": true
},
{
"label": "Document local R package",
"command": "Rscript -e \"devtools::document(roclets = c('rd', 'collate', 'namespace'))\"",
"cwd": "$ZED_WORKTREE_ROOT",
"use_new_terminal": false,
"allow_concurrent_runs": false
},
{
"label": "Check local R package",
"command": "Rscript -e \"devtools::check()\"",
"cwd": "$ZED_WORKTREE_ROOT",
"use_new_terminal": false,
"allow_concurrent_runs": false
},
{
"label": "Run all R tests",
"command": "Rscript -e \"testthat::test_dir('tests/testthat')\"",
"cwd": "$ZED_WORKTREE_ROOT",
"use_new_terminal": false,
"allow_concurrent_runs": false,
"reveal": "always",
"show_summary": true,
"show_output": true
},
{
"label": "Run current R file test",
"command": "Rscript -e \"testthat::test_file('$ZED_RELATIVE_FILE')\"",
"cwd": "$ZED_WORKTREE_ROOT",
"use_new_terminal": false,
"allow_concurrent_runs": false,
"reveal": "always",
"show_summary": true,
"show_output": true
},
{
"label": "Run test_that test", // Can be triggered, without a keyboard shortcut
// or clicking on the run button, by toggling the code action menu (Ctrl+.)
"command": "Rscript",
"cwd": "$ZED_WORKTREE_ROOT",
"args": [
"-e",
"\"testthat::test_file(\\\"${ZED_FILE}\\\", desc = \\\"${ZED_CUSTOM_desc}\\\")\""
],
"tags": ["r-test"]
},
{
"label": "Source current file",
"command": "Rscript -e \"source('$ZED_RELATIVE_FILE', echo = TRUE)\"",
"cwd": "$ZED_WORKTREE_ROOT",
"use_new_terminal": false,
"allow_concurrent_runs": false,
"reveal": "always",
"show_summary": true,
"show_output": true
}
]
- For a different keyboard shortcut for tasks, read this section in the official Zed documentation.
Caveats
- A custom startup message in
.Rprofilecan potentially cause the the LSP message headers to be decoded improperly and prevent the language server from starting in Zed (#7).
Known issues
Check out the project's issue list for a list of unresolved issues. Feel free to fix any of them and send us a pull request!