Skip to content

ilyaZar/Rgolem.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rgolem.nvim

R.nvim companion plugin for golem Shiny app development in Neovim.

Features

  • Golem project detection -- automatically detects when you are working inside a golem project
  • Context-aware keymaps -- shortcuts for golem::document_and_reload() and golem::run_dev(), only active in golem projects
  • Golex -- a small nvim plugin utility for creating and managing throwaway golem Shiny app skeletons across multiple directories ("shelves"); useful for rapid prototyping and testing of new golem skeleton apps during golem development

Requirements

  • Neovim >= 0.10
  • R.nvim
  • R with the golem package installed

Installation

Rgolem.nvim hooks into R.nvim's opts table. Set it up as a dependency of R.nvim:

{
  dir = "path/to/Rgolem.nvim",
  name = "Rgolem.nvim",
  lazy = true,
},
{
  "R-nvim/R.nvim",
  dependencies = { "Rgolem.nvim" },
  opts = function(_, opts)
    require("rgolem").setup(opts)
  end,
}

The setup() function accepts an optional second table for Rgolem-specific settings:

require("rgolem").setup(opts, {
  -- default skeleton directory (always present as first shelf entry)
  golex_dir = "/tmp/golskels",         -- default
  -- path to JSON file that persists shelf list across sessions
  shelves_path = vim.fs.joinpath(
    vim.fn.stdpath("data"), "rgolem", "shelves.json"
  ),                                    -- default
  -- argv used to open an existing golex; selected path is appended
  -- bare { "nvim" } is wrapped in a terminal launcher on linux
  golex_open_cmd = { "nvim" },

  -- examples:
  -- golex_open_cmd = { "code" },
  -- golex_open_cmd = { "positron" },
  -- golex_open_cmd = { "rstudio" },
})

When golex_open_cmd is unset, Rgolem falls back to a Linux Neovim launcher chain (xdg-terminal-exec, then ghostty, then alacritty). Setting golex_open_cmd = { "nvim" } uses the same terminal-wrapper logic. GUI editors like VS Code, Positron, and RStudio do not need a terminal wrapper here.

If you also use rarr.nvim or a similar R.nvim companion, chain them in the same opts function:

opts = function(_, opts)
  require("rarr").setup(opts)
  require("rgolem").setup(opts)
end,
use {
  "R-nvim/R.nvim",
  requires = { "ilyaZar/Rgolem.nvim" },
  config = function()
    local opts = {}
    require("rgolem").setup(opts)
    require("r").setup(opts)
  end,
}
Plug 'ilyaZar/Rgolem.nvim'
Plug 'R-nvim/R.nvim'
-- in your init.lua
local opts = {}
require("rgolem").setup(opts)
require("r").setup(opts)

Commands

Golem Commands

These send R expressions to your running R session via R.nvim:

Command Action
:GolemDocumentReload golem::document_and_reload()
:GolemRunDev golem::run_dev()

Golex Commands

Manage golem app skeletons under the active shelf directory (defaults to /tmp/golskels/):

Command Action
:Rgolex open the golex manager
:Rgolex 5 create golex05 directly
:Rgolex myapp create myapp directly
:Rgolex! auto-increment to the next golexNN
:Rgx alias for :Rgolex
:rgx lowercase alias (expands to :Rgx)

Keymaps

Set automatically in buffers inside golem projects:

Key Mode Action
<C-g> n golem::document_and_reload()
<C-S-g> n golem::run_dev()

These keymaps are context-aware: they are only active when the current buffer is inside a detected golem project.

Golex -- Skeleton Manager

Golex is a small utility for quickly creating and managing throwaway golem Shiny app skeletons. It is useful during golem package development when you need fresh app skeletons to test scaffolding, module generation, or deployment workflows.

Skeletons are created via golem::create_golem() inside the active shelf directory (defaults to /tmp/golskels/). You can manage multiple shelf directories and switch between them at runtime using the shelf picker (see below).

Three Modes

1. Manager UI (:Rgolex)

Opens a floating window listing all existing skeletons in the active shelf, with an input line for creating new ones:

2. Direct create (:Rgolex N or :Rgolex name)

Creates a skeleton without opening the UI. Numeric input is interpreted as a golex number; anything else is used as-is:

Input Resolved name
7 golex07
12 golex12
myapp myapp

If the directory already exists, you are prompted to confirm the overwrite.

3. Auto-increment (:Rgolex!)

Creates the next golexNN skeleton (finds the highest existing number and adds 1). No UI, no prompts.

Manager Keybindings

Inside the golex manager floating window:

Key Action
j/k navigate entries
CR create or open selected entry
d delete selected entry
S open shelf picker (switch dirs)
q close
Esc close
  • Input line (top): type a number or name, press CR to create
  • Existing entries (below): navigate with j/k, press CR for the action menu, use h/l or arrow keys to switch between open and overwrite, then CR to confirm, O to jump straight to overwrite, or d to delete (with confirmation)
  • Aborting a confirmation prompt returns you to the manager

Shelf Picker (Multiple Directories)

Press S in the main manager to open the shelf picker. This lets you manage the list of toplevel directories ("shelves") that hold golem skeletons.

The shelf picker works the same way as the main manager:

Key Action
j/k navigate shelf entries
CR switch to selected shelf (returns to manager)
d remove shelf from list (default is protected)
q back to manager
Esc back to manager
S back to manager
  • Input line (top): type a path, press CR to add it as a new shelf and switch to it
  • Existing entries (below): the active shelf is marked with *; press CR to switch, or d to remove (the default shelf cannot be removed)

The shelf list persists across Neovim sessions in a JSON file (see shelves_path, which defaults to ~/.local/share/nvim/rgolem/shelves.json, in the configuration section above).

Notifications

Errors are displayed in a floating window for 20 seconds; success messages for 10 seconds. Both auto-dismiss and can be closed early with q or Esc.

Golem Project Detection

A buffer is detected as being inside a golem project when an ancestor directory contains a DESCRIPTION file and inst/golem-config.yml exists.

Detection also works for terminal buffers by parsing the term:// URI scheme.

Health Check

Run :checkhealth rgolem to verify your setup. It checks:

  • Neovim version (>= 0.10)
  • R.nvim availability
  • Rscript on PATH
  • golem R package installed

License

MIT

About

R.nvim companion plugin for golem Shiny app development in Neovim.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages