R support for REPLConnect.nvim — connect Neovim to a running R session (designed for the arf console).
The repository has two parts:
replconnect/ — an R package (Rust core via extendr) that serves the
session's variables, a grid data viewer, runtime completion, history and
plots to Neovim over a Unix-domain socket, using the REPLConnect protocol.
Requests are handled on R's main thread while R is idle at the prompt.lua/replconnect/r.lua and plugin/replconnect-r.lua — a Neovim plugin
that registers R as a language with the replconnect.nvim core.unigd (plot capture), tibble, data.table
Install the R package from r-universe, which provides prebuilt binaries (no Rust toolchain needed):
install.packages(
"replconnect",
repos = c("https://arnold-c.r-universe.dev", "https://cloud.r-project.org")
)
Or with pak:
# install.packages("pak")
pak::repo_add(arnold = "https://arnold-c.r-universe.dev")
pak::pkg_install("replconnect")
To build from source instead (requires Cargo and rustc):
pak::pak("arnold-c/REPLConnect.R/replconnect")
Add this repository to Neovim's runtimepath alongside replconnect.nvim, e.g. with lazy.nvim:
{
"arnold-c/REPLConnect.R",
dependencies = { "<owner>/REPLConnect.nvim" }
}
Add this to your ~/.Rprofile
if (interactive()) {
replconnect::start()
replconnect::capture_plots(TRUE)
}
renv gives each project an isolated library, and R skips ~/.Rprofile
when a project has its own .Rprofile (as renv projects do). To use
replconnect in renv projects without adding it as a project dependency,
install it into a separate personal library and tell renv about it.
From a session outside any renv project (e.g. R --vanilla), install
into a dedicated library. Use a local checkout or r-universe:
lib <- path.expand("~/.R/dev-library")
dir.create(lib, recursive = TRUE, showWarnings = FALSE)
install.packages(
"/path/to/REPLConnect.R/replconnect", # local source checkout
lib = lib,
repos = NULL,
type = "source"
)
# or: install.packages("replconnect", lib = lib,
# repos = "https://arnold-c.r-universe.dev")
Add to ~/.Renviron (use an absolute path):
RENV_CONFIG_USER_PROFILE=TRUE
RENV_CONFIG_EXTERNAL_LIBRARIES=/Users/<you>/.R/dev-library
user.profile makes renv source ~/.Rprofile on activation, and
external.libraries adds the library to .libPaths() without recording
it in renv.lock.
Use this in ~/.Rprofile, which works both inside and outside renv
projects:
if (interactive()) {
local({
lib <- path.expand("~/.R/dev-library")
if (requireNamespace("replconnect", lib.loc = c(.libPaths(), lib), quietly = TRUE)) {
replconnect::start()
replconnect::capture_plots(TRUE)
}
})
}
| Function | Purpose |
|---|---|
start() |
Start serving the session over a socket |
serving() |
Check whether the server is running |
shutdown() |
Stop the server |
capture_plots() |
Toggle forwarding of plots to Neovim |
record_history() |
Record console history for Neovim |
Tests live in replconnect/tests/ (testthat), spec/ and tests/ (Neovim),
and the Rust core in replconnect/src/rust/core (cargo test).
See replconnect/LICENSE.