VS Code as R IDE
October 5, 2021 — August 22, 2021
VS Code as an R IDE, because I do not like RStudio.
vscode-R provides R session support from inside VS Code.1 The home page for the integration is the vscode-R Wiki. Lots of nice conveniences, e.g. Interactive viewers and rmarkdown. support. R needs the language server installed for deep language integration (step debugger etc) to go. Although, TBH I haven’t found use for it yet. My use of R is more to generate reports than to create packages, though, so perhaps I am not the target audience.
The corresponding extension is
Debugger support is via vscDebugger:
The following config in settings.json
is helpful for keeping it fast with R development, since it ignores blogdown cruft and miscellaneous R packaging stuff.
"files.watcherExclude": {
"**/env/**": true,
"**/output/**": true,
"**/renv/**": true
},
"search.useGlobalIgnoreFiles": true,
"files.exclude": {
"content/**/*.html": true
},
"search.exclude": {
"content/**/*.bib": true,
"content/**/*.yaml": true
},
"cSpell.enableFiletypes": [
"rmarkdown",
"rmd"
],
For editing blogdown, an in-app browser preview can be useful.
Plotting runs a tame webserver, httpgd: Asynchronous http server graphics device for R.:
install.packages("httpgd")
hgd()
hgd_browse()
x = seq(0, 3 * pi, by = 0.1)
plot(x, sin(x), type = "l")
dev.off()
For philosophy see Kun Ren’s post, Using httpgd in VSCode: A web-based SVG graphics device, which also explains how plotting works in R more broadly.
1 Positron
Positron is a VS Code fork specialising in R-friendly experiences with some
How is Positron different from RStudio, VS Code, or Jupyter notebooks?
- Positron has first-class, built-in support for R and/or Python via an integrated Console, with extensibility options for other languages in the future. This native support includes specialized views and panes throughout Positron such as a Data Explorer, Connections Pane, Variables Pane, and more.
- Positron runs the interpreter separately from the IDE, so unlike in RStudio a crash in R/Python won’t always crash the IDE. It also means that you can swap between versions of your preferred language on the fly without a full reload of the IDE, just the integrated console.
- Positron supports VS Code compatible extensions (
.vsix
files), providing extensibility of capabilities beyond the core IDE itself. By building on Code OSS, Positron gets rich text editor capabilities and access to 1,000s of community extensions out of the box. Read more about using extensions with Positron.- Positron is deeply focused on native data science workflows; it provides a batteries-included and cohesive experience beyond that of a general-purpose IDE or text editor such as VS Code.
posit-dev/positron: Positron, a next-generation data science IDE
Footnotes
In some locations this is referred to as Ikuyadeu.r? AFAICT they are the same but there is renaming in-progress.↩︎