Skip to content

Support for running R in remote machine#515

Merged
jalvesaq merged 14 commits into
mainfrom
remote_R
Mar 15, 2026
Merged

Support for running R in remote machine#515
jalvesaq merged 14 commits into
mainfrom
remote_R

Conversation

@jalvesaq

Copy link
Copy Markdown
Member

New options:

  • remote_compl_dir
  • remote_R_addr
  • local_nvim_addr

New options:
 - remote_compl_dir
 - remote_R_addr
 - local_nvim_addr
@jalvesaq

Copy link
Copy Markdown
Member Author

On this branch, it's possible to run R on a remote machine while rnvimserver runs on the local machine. I moved the apps directory from nvimcom/src to the root of the repository, named as rnvimserver. Now, it's compiled by make and gcc. The nvimcom package is built by tar (not R CMD build). This way, R doesn't need to be installed on the local machine.

Comment thread doc/R.nvim.txt Outdated
|remote_compldir| Mount point of remote cache directory
|remote_compl_dir| Mount point of remote cache directory
|remote_R_addr| Address of remote R host
|local_nvim_addr| Address of local Neovim machine

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you checked SSH_CONNECTION to replace both of the above by simply remote_R_host?

@PMassicotte

Copy link
Copy Markdown
Collaborator

With the new config, it means that people will have to reconfigure R.nvim every time they want to connect to a new remote. Would it be better to have a .rnvim config file in the directory of the R project?

@mschilli87

Copy link
Copy Markdown

Personally I would prefer being able to overwrite these settings with good old environment variables. Then this sort of project-specific environment thing could be configured on the shell level rather than in R. For example, I might work on the same project (synced via Git) in several environments. An example: When I am connected to my work LAN, I want to use the local big compute server to run my code. But when I go home and continue working in the evening, I might prefer sending the R commands from my notebook to my workstation in the other room rather than connecting to the work server via VPN. Then again, when a job gets too heavy for my workstation, I might reconsider, turn on the VPN and switch to working on the compute server. So for me, the remote is not so much project dependent as it is situational and it would be easy to write simple shell scripts that (dis-)connect VPN connections (if needed) and change a few environment variables.

@jalvesaq

Copy link
Copy Markdown
Member Author

With the new config, it means that people will have to reconfigure R.nvim every time they want to connect to a new remote. Would it be better to have a .rnvim config file in the directory of the R project?

Yes, maybe, .rnvim.lua or rnvim_config.lua. The advantage of .nvim.lua is that it is less distracting when looking for files. The advantage of rnvim_config.lua is that it is easier for the user to remember that there are specific configurations in the directory. The extension .lua will make it easier to edit. What do you think is better?

Personally I would prefer being able to overwrite these settings with good old environment variables.

Would something like this work for your case?

  remote_compl_dir = vim.env.PROJ_XYZ_CMP_DIR,
  remote_R_addr = vim.env.PROJ_XYZ_REMOTE_ADDRESS,
  local_nvim_addr = vim.env.PROJ_XYZ_LOCAL_ADDRESS,

@jalvesaq

Copy link
Copy Markdown
Member Author

Have you checked #511 (comment) to replace both of the above by simply remote_R_host?

I didn't forget this, but I don't know how to configure ssh in this way. From your explanation, I assumed that this would work:

   remote_compl_dir = "hostname",

Can you try it?

@mschilli87

Copy link
Copy Markdown

@jalvesaq: Sorry for not being clearer in my original message. This is what I meant:

Right now, one needs to i) specify the remote host via remote_R_addr and ii) the (correct!) local IP via local_nvim_addr.

I have two issues with this:

  1. As you pointed out, I can use [user@]host[.domain] or even just an SSH alias instead of an IP address for remote_R_addr. That's why IMHO remote_r_host would be a more intuitive name for that parameter.
  2. As you pointed out as well, my local machine might have more than one IP address. My suggestion was to use ssh's SSH_CONNECTION environment variable by running
ssh <host> -- 'printf "$SSH_CONNECTION"'

(where <host> is the value of remote_r_addr/remote_r_host) to i) resolve remote_r_addr/remote_r_host to the correct IP address (if required for anything) and (more imporantly) ii) determine local_nvim_addr automatically, without the need for the user to determine it at all.
No special configuration should be required.

The last part is the most important for me as I would usually use remote R session when using a less powerful machine, like my notebook. That machine though I typically use from different networks, typically using DHCP to get a non-static IP. Thus, not having to keep track of it myself would be nice.

I hope this clarifies my points a bit.

 - Rename `remote_R_addr` as `remote_R_host`.
 - Remove `local_nvim_addr` superfluous.
 - Make `remote_compl_dir` optional in a specific case.
@PMassicotte

Copy link
Copy Markdown
Collaborator

Would something like this work for your case?

  remote_compl_dir = vim.env.PROJ_XYZ_CMP_DIR,
  remote_R_addr = vim.env.PROJ_XYZ_REMOTE_ADDRESS,
  local_nvim_addr = vim.env.PROJ_XYZ_LOCAL_ADDRESS,

I really like the idea.

@jalvesaq

Copy link
Copy Markdown
Member Author

Thanks, @mschilli87! I renamed remote_R_addr as remote_R_host, and removed local_nvim_addr.
If the option remote_compl_dir is "", it will be a copy of compldir.

However, there will be a bug if the user connects to the server through SSH and then starts nvim to run both Neovim and R on the remote machine. I will fix this...

@jalvesaq

Copy link
Copy Markdown
Member Author

With the new config, it means that people will have to reconfigure R.nvim every time they want to connect to a new remote. Would it be better to have a .rnvim config file in the directory of the R project?

I implemented it as rnvim_config.lua, but I can change it to .nvim.lua, or support both...

@jalvesaq

Copy link
Copy Markdown
Member Author

The correct way of using an environment variable is:

  remote_R_host = vim.env.PROJ_XYZ_R_HOST and vim.env.PROJ_XYZ_R_HOST or "",

Comment thread doc/R.nvim.txt Outdated
Co-authored-by: Marcel Schilling <mschilling@ub.edu>
@PMassicotte

Copy link
Copy Markdown
Collaborator

With the new config, it means that people will have to reconfigure R.nvim every time they want to connect to a new remote. Would it be better to have a .rnvim config file in the directory of the R project?

I implemented it as rnvim_config.lua, but I can change it to .nvim.lua, or support both...

Excellent!

@jalvesaq jalvesaq marked this pull request as ready for review March 15, 2026 13:51
@jalvesaq jalvesaq requested a review from Copilot March 15, 2026 13:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reorganizes/builds rnvimserver as a standalone binary (instead of under nvimcom/src/apps), expands remote-R support (ssh/sshfs flow), and updates Neovim-side Lua and docs to match the new layout and remote workflow.

Changes:

  • Added/rewired a standalone rnvimserver C codebase (TCP server, utilities, completion/hover/signature/definition helpers) and updated build files to compile it from rnvimserver/.
  • Updated Lua remote-R workflow (sshfs mount, ssh execution, nvimcom tarball handling) and switched LSP startup to run rnvimserver from PATH.
  • Updated nvimcom client connection logic for remote sessions, and consolidated/updated documentation for remote access.

Reviewed changes

Copilot reviewed 26 out of 46 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
rnvimserver/utilities.h New shared utility header (buffer, JSON helpers, etc.).
rnvimserver/utilities.c New utility implementations (buffer growth, file read, JSON escape/cutters, fuzzy search).
rnvimserver/tcp.h New TCP interface for rnvimserver.
rnvimserver/tcp.c New TCP server implementation and message parsing/dispatch.
rnvimserver/signature.h New signature feature header.
rnvimserver/signature.c Updated include path for shared common.h.
rnvimserver/roxygen.h New roxygen completion header.
rnvimserver/roxygen.c Updated include path for shared common.h.
rnvimserver/rnvimserver.c Updated include path and removed localtmpdir usage.
rnvimserver/rhelp.h New Rhelp completion header.
rnvimserver/rhelp.c Updated include path for shared common.h.
rnvimserver/resolve.h New resolve/docs header.
rnvimserver/resolve.c Updated include path for shared common.h.
rnvimserver/obbr.h New object-browser helper header.
rnvimserver/obbr.c Updated include path and moved object browser temp files to tmpdir.
rnvimserver/Makefile.win Build rnvimserver against ../nvimcom/src/common.c.
rnvimserver/Makefile Build rnvimserver against ../nvimcom/src/common.c.
rnvimserver/lsp.h New header for LSP-facing helpers.
rnvimserver/logging.h New logging header (Debug_NRS gated).
rnvimserver/logging.c New logging implementation.
rnvimserver/hover.h New hover feature header.
rnvimserver/hover.c Updated include path for shared common.h.
rnvimserver/global_vars.h New header consolidating rnvimserver globals.
rnvimserver/definition.h New definition feature header.
rnvimserver/definition.c New definition resolution logic (incl. srcref parsing and R fallback).
rnvimserver/data_structures.h New header for package/cache/object-browser structures.
rnvimserver/data_structures.c New data/cache/object-browser data structures and update logic.
rnvimserver/complete.h New completion header.
rnvimserver/complete.c Updated include path for shared common.h.
rnvimserver/chunk.h New chunk completion header.
rnvimserver/chunk.c Updated include path for shared common.h.
resources/before_rns.R Remote-aware nvimcom install/update flow; changes working directory to compldir.
nvimcom/src/nvimcom.c Adds remote rnvimserver IP selection based on SSH session; uses derived address in connect().
nvimcom/src/Makevars.win Stops building apps/ as part of the R package build.
nvimcom/src/Makevars Stops building apps/ as part of the R package build.
nvimcom/src/apps/global_vars.h Removed (apps directory no longer used for rnvimserver).
nvimcom/DESCRIPTION Bumps nvimcom version/date.
lua/r/server.lua Builds rnvimserver, manages sshfs mount, remote init/build flows; starts LSP via env.
lua/r/run.lua Remote-R env setup and temp file handling changes; sets additional RNVIM env vars in start options.
lua/r/lsp/init.lua Changes LSP startup signature and runs rnvimserver from PATH.
lua/r/edit.lua Remote cleanup: unmount sshfs instead of rmdir on tmpdir.
lua/r/config.lua Renames/expands remote options; adds per-directory rnvim_config.lua override support; remote ssh adjustments.
lua/r/browser.lua Uses tmpdir instead of removed localtmpdir.
doc/remote_access.md Removed (documentation moved/rewritten into main help).
doc/R.nvim.txt Adds per-directory config docs; updates remote access docs/options.
.gitignore Adjust ignore patterns to new rnvimserver binary location.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lua/r/server.lua Outdated
Comment thread lua/r/server.lua Outdated
Comment thread nvimcom/src/nvimcom.c
Comment thread lua/r/run.lua
Comment thread doc/R.nvim.txt Outdated
Comment thread lua/r/config.lua Outdated
Comment thread doc/R.nvim.txt Outdated
jalvesaq and others added 6 commits March 15, 2026 11:04
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@jalvesaq

Copy link
Copy Markdown
Member Author

Thank you, @mschilli87 and @PMassicotte! I will merge it now.

@jalvesaq jalvesaq merged commit 6813c1a into main Mar 15, 2026
9 checks passed
@jalvesaq jalvesaq deleted the remote_R branch March 15, 2026 14:19
@PMassicotte

Copy link
Copy Markdown
Collaborator

Good job @jalvesaq !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants