With VSCode you can configure a keybinding to run artibrary #rstats code, including {rstudioapi}
calls in just a matter of seconds. That code can refer to things like the current selection, cursor location, or the current file.
For example here’s me making myself a knit
button, where the placeholder $$
refers to the current file:
{
"description": "knit to html",
"key": "ctrl+i",
"command": "r.runCommandWithEditorPath",
"when": "editorTextFocus",
"args": "rmarkdown::render(\"$$\", output_format = rmarkdown::html_document(), output_dir = \".\", clean = TRUE)"
}
And here’s a shortcut that opens a window to interactively edit the spatial object the user has the cursor on or has selected. In this case $$
refers to that object:
{
"key": "e",
"name": "mapedit object",
"type": "command",
"command": "r.runCommandWithSelectionOrWord",
"args": "mapedit::editMap(mapview::mapview($$))"
}
Snippets are also easy. There’s about 3 different ways to achieve inserting text, all in the same simple json config style:
{
"key": "ctrl+shift+m",
"command": "type",
"when": "editorLangId == r || editorLangId == rmd && editorTextFocus",
"args": { "text": " %>% " }
}
Although RStudio addins are supported in VSCode, many things popular addins do can be done with a few lines of config. It’s a keyboard shortcut lover’s dream - I’d argue even more so than ESS. RStudio users should campaign for this!