Hacker News Viewer

A Better R Programming Experience Thanks to Tree-sitter

by sebg on 4/16/2026, 9:14:02 PM

https://ropensci.org/blog/2026/04/02/tree-sitter-overview/

Comments

by: tylermw

I read this article a week or so ago and immediately implemented a VS Code extension that I&#x27;ve always wanted: a static analysis tool for targets pipelines. targets is an R package which provides Make-like pipelines for data science and analysis work. You write your pipeline as a DAG and targets orchestrates the analysis and only re-runs downstream nodes if upstream ones are invalidated and the output changes. Fantastic tool, but at a certain level of complexity the DAG becomes a bit hard to navigate and reason about (&quot;wait, what targets are downstream of this one again?&quot;). This isn&#x27;t really a targets problem, as this will happen with any analysis of decent complexity, but the structure targets adds to the analysis actually allows for a decent amount of static analysis of the environment&#x2F;code. Enter tree-sitter.<p>I wrote a VS Code extension that analyzes the pipeline and provides useful hover information (like size, time last invalidated, computation time for that target, and children&#x2F;parent info) as well as links to quickly jump to different targets and their children&#x2F;parents. I&#x27;ve dogfooded the hell out of it and it&#x27;s already vastly improved my targets workflow within a week. Things like providing better error hints in the IDE for targets-specific malformed inputs and showing which targets are emitting errors really take lots of the friction out of an analysis.<p>All that to say: nice work on extending tree-sitter to R!<p>tarborist: targets + tree-sitter <a href="https:&#x2F;&#x2F;open-vsx.org&#x2F;extension&#x2F;tylermorganwall&#x2F;tarborist" rel="nofollow">https:&#x2F;&#x2F;open-vsx.org&#x2F;extension&#x2F;tylermorganwall&#x2F;tarborist</a><p>GH: <a href="https:&#x2F;&#x2F;github.com&#x2F;tylermorganwall&#x2F;tarborist" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;tylermorganwall&#x2F;tarborist</a>

4/17/2026, 2:29:51 AM


by: nomilk

The article makes out like auto completion and help on hover are new things, but RStudio IDE has had them for years and years.<p>R&#x2F;RStudio was my first language&#x2F;IDE. I was horribly shocked when moving into other languages to discover they didn&#x27;t have things you got out of the box with R&#x2F;RStudio. &quot;You mean I have to <i>look up</i> documentation for a function&#x2F;method!?! - that&#x27;s supposed to be automatic!&quot;.<p>R has a bunch of features which other languages lack to the degree that it&#x27;s a rude shock to learn that other ecosystems lack them. One is the REPL with extremely convenient RStudio keyboard shortcuts to run lines of code (to achieve similar with ruby, I have an elaborate neovim&#x2F;slime setup that took hours to configure and still isn&#x27;t as good as RStudio gives out of the box).<p>A sign of a brilliant tool is when an idiot can get more done with it than an expert can with alternatives.

4/17/2026, 12:14:14 AM


by: epistasis

Tree-sitter is one of the finer engineering products out there, it enables so much. Thanks to its creator and everyone who has contributed to this project and its many grammars!

4/16/2026, 10:52:58 PM


by: dash2

I&#x27;ve been thinking about an R package, or maybe a more general treesitter-based package, to reorganize functions in a project. Something like a tui which shows you functions in files in folders and lets you copy and paste them around; and maybe use graph analysis to automate this, analysing function dependencies and putting each &quot;community&quot; of functions into one file.<p>Is there any interest in this? There are per-language complexities, for example R functions are often preceded by a roxygen block which ought to travel with it. Has anyone done something similar?

4/17/2026, 6:45:41 AM


by: fn-mote

Do the tools built on this understand dplyr pipelines and columns in the data frames appearing as bare variables in the code? If so, I’m really impressed. R does some unusual stuff.

4/17/2026, 12:06:05 AM


by: moffkalast

People really do still be using R in 2026. Old habits I guess.

4/17/2026, 9:20:41 AM


by: TacticalCoder

I moved to tree-sitter inside Emacs a while ago and I&#x27;d say tree-sitter is much easier than it looks like.<p>I had a first little use case... For whatever reason the options to align <i>let</i> bindings in Clojure code, no matter if I tried the &quot;semantic&quot; or Tonsky&#x27;s semi-standard way of formatting Clojure code (several tools adopted Tonsky&#x27;s suggestion) and no matter which option&#x2F;knob I turned on, I couldn&#x27;t align like I wanted.<p>I really, really, really hate the pure horrible chaos of this:<p><pre><code> (let [abc (+ a 2) d (inc b) vwxyz (+ abc d)] ... </code></pre> But I love the perfection of this [1]:<p><pre><code> (let [abc (+ a 2) d (inc b) vwxyz (+ abc d)] ... </code></pre> And the <i>cljfmt</i> is pretty agnostic about it: I can both use cljfmt from Emacs and have a hook forcing <i>cljfmt</i> and it&#x27;ll align everything but it won&#x27;t mess with those nice vertical alignments.<p>Now, I know, I know: it is <i>supposed</i> to work directly from <i>cljfmt</i> but many options are, still in the latest version, labelled as experimental and I simply couldn&#x27;t make it work on my setup, no matter which knob I turned on.<p>So what did I do? Claude Code CLI, tree-sitter, and three elisp functions.<p>And I added my own vertical indenting to Clojure <i>let</i> bindings. And it&#x27;s compatible with cljfmt (as in: if I run cljfmt it doesn&#x27;t remove my vertical alignments).<p>I&#x27;d say the tree-sitter syntax tree is incredibly verbose (and has to be) but it&#x27;s not that hard to use tree-sitter.<p>P.S: and I&#x27;m not alone in liking this kind of alignment and, no, we&#x27;re not receptive to the &quot;but then you modify one line and several lines are detected as modified&quot;. And we&#x27;re less receptive by the day now that we begin to had tools like diff&#x27;ing tools that are indentation-agnostic and only do AST diffs.

4/17/2026, 12:09:05 AM