VS Code as R IDE

October 6, 2021 — August 22, 2021

computers are awful
number crunching
plain text
R
statistics
UI
workflow
Figure 1: VS Code can be dressed up as an R IDE with the balance of form and function you would expect

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.

install.packages("languageserver")

The corresponding extension is

ext install REditorSupport.r-lsp

Debugger support is via vscDebugger:

install.packages(c('R6', 'jsonlite'))
install.packages('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.

Footnotes

  1. In some locations this is referred to as Ikuyadeu.r? AFAICT they are the same but there is renaming in-progress.↩︎