17.1 Why Fork GNU R Instead of Rewriting It?
17.1.1 Question
Should I patch GNU R’s C sources to build a multi-interpreter design, or rewrite the interpreter from scratch?
17.1.2 Context
GNU R is a mature codebase, refined over decades, and its C API is the surface packages build on. On 2026-10-21, 5,569 of the 25,474 packages in CRAN’s package database declared NeedsCompilation: yes, meaning they ship C, C++ or Fortran code that is compiled against that API when the package is installed (tools::CRAN_package_db()).
Other implementations of R exist, and none replaced GNU R for everyday work. Renjin runs R on the JVM and translates package C and Fortran to JVM bytecode with its GCC-Bridge, and not every package builds that way. FastR, on GraalVM, implements R’s C API and compiles a package’s native code against it at install time; it shipped as a GraalVM component and is now in maintenance mode. Rho, formerly CXXR, refactored GNU R into C++ and could not run any package whose native code used USE_RINTERNALS, which shut out Rcpp and everything built on it; its development is suspended. pqR is a modified GNU R, and Riposte was a research virtual machine. For the separate interpreters, packages with compiled code were a large part of the cost.
Compatibility failures cascade. A package that fails takes down every package that imports it, so an interpreter that runs most of CRAN can still fail the analysis a user actually runs. The stacks people rely on, such as Bioconductor, Seurat or tidymodels, sit on deep dependency trees with compiled code in them.
17.1.3 Constraints
The C API must be preserved: a package’s source must compile and run against the fork unchanged. The binary layout is free to change. threaded-r is binary-incompatible with stock R by design (its decision D3), and an ABI tag makes a compiled package built for stock R refuse to load instead of corrupting memory.
The native-package ecosystem is large and varied. Packages hold pointers into R objects, assume single-threaded process-global state, and call R functions from C code. No specification documents all these assumptions. They live in undocumented behavior and code patterns.
Building multi-interpreter support into GNU R’s C sources means modifying a large codebase, invasively. Global variables become per-thread or per-interpreter state, and process-level APIs become interpreter-level APIs. Every change risks breaking something a package relied on without the documentation saying so.
17.1.4 Options considered
Rewrite from scratch. Build a new interpreter that implements R syntax and semantics, with a compatible C API. The r-in-rust project (rrs) explores this approach. A new design can have a cleaner memory model and concurrency from the start. But it has to reimplement the whole base library: base alone has 1,407 bindings, 210 of them primitives, as counted in threaded-r’s release build, and GNU R’s shipped namespaces export 2,951 functions. The compatibility surface is unforgiving. Small semantic differences make packages fail, and packages that depend on unspecified behavior of the C API break. When I made this choice, a rewrite looked too risky for a system that has to run CRAN.
Embed or extend via packages only. Do not modify the core interpreter. Provide extension points via packages. This preserves compatibility because the core never changes. But extension points are limited. Package code cannot reach interpreter internals. It cannot create new interpreter instances. It cannot control garbage collection or memory allocation at the interpreter level. This approach cannot achieve the multi-interpreter goal. It can only extend R’s capabilities, not restructure the interpreter itself.
Fork and patch. Use GNU R’s source code as a base and apply a quilt-style patch series over pristine fetched sources. The patches implement multi-interpreter support by modifying the C code in place. This keeps the C API, because I change the implementation and not the interface, and it keeps the semantics, because the algorithms and data structures stay. Packages compile unchanged, though they have to be compiled for the fork. pqR and Rho both modified GNU R’s own sources, and threaded-r does the same. The cost is maintaining patches against upstream drift.
17.1.5 Decision
I fork GNU R and apply patches, instead of rewriting it or extending it through packages.
17.1.6 Reasons
The C API decided it. Thousands of CRAN packages ship compiled code that calls it, and when I made this choice no reimplementation had shown it could serve them. Extension through packages cannot reach the interpreter level at all.
Patching keeps compatibility because the C API and most of the implementation stay intact. I move global state into per-thread and per-interpreter structures, which changes the internals and leaves the interface alone.
The record on other implementations points the same way. None of the separate interpreters, Renjin, FastR or Riposte, displaced GNU R, and Rho, which kept GNU R’s sources, still lost every package whose compiled code used USE_RINTERNALS.
I am running both approaches on purpose. Forking GNU R keeps CRAN and tests the apartment model on a real ecosystem. The r-in-rust project rewrites to answer a different question: can a safe R interpreter be built without GNU R’s C core and its global state? These are separate bets with separate success criteria, and either could fail.
Maintaining patches against upstream drift is sustainable if the patch count stays manageable and upstream major-version changes occur infrequently enough for my resources to keep pace.
17.1.7 Consequences
I inherit GNU R’s technical debt and design choices. I cannot fix old mistakes in the C code, only work around them. As upstream R evolves, my patches have to follow, and large upstream changes can mean extensive repatching.
Each GNU R release has to be reviewed for changes that touch my patches. threaded-r keeps the series in a quilt-style series file, applies it with patch, and checks every patch with make check on two build lanes. At milestones it also reruns a corpus of the 29 base and recommended packages on a THREAD worker and a conformance suite with workers as threads.
I commit to C API compatibility, and it costs less than it sounds. The layout of R objects is mine to change, because SEXPREC is opaque to package code: since R 4.2.0, defining USE_RINTERNALS no longer exposes it. What I cannot touch is the surface: no renaming an exported symbol, no changing a signature or a public constant, no altering documented behavior. Packages still have to be reinstalled for the fork, because it changes the state structures and accessor macros that compiled code can depend on, and the ABI tag enforces that.
The patch series can become unmaintainable if upstream makes large structural changes. Rho, the closest precedent, has its development suspended indefinitely. threaded-r tries to stay maintainable by keeping each patch small and focused, testing every one, and staying close to upstream.
17.1.8 Evidence that would change my mind
If the patch series becomes unmaintainable against upstream drift, I would reconsider. If GNU R evolves in ways that need extensive rework of the patches, either a rewrite or a long-term divergent fork becomes necessary. The series stood at 149 patches at the R3 release candidate review, with the Windows port merged, and at 153 on 2026-08-26 (docs/README.md on the main branch).
If CRAN packages adopted a new standard ABI or broke compatibility for other reasons, the compatibility constraint would weaken. If a significant fraction of packages moved to a new interpreter, the incentive to keep GNU R compatibility would disappear.
This is the condition I am closest to meeting, and my own other project is the one moving it. r-in-rust set out to reimplement R and now loads compiled CRAN packages: mime installs from source and loads, Rcpp builds and loads, and in the census of 2026-08-18 twenty-eight of the thirty most downloaded compiled packages installed and loaded.
That is not yet compatibility with CRAN at large, and the rest of the base library is a long road. But the reason I wrote “I will reassess” was that the native-package boundary looked impassable from a new interpreter, and it is passable. I am keeping the fork, and the argument for it is now about how much work the other path still needs, not about whether it exists.
Where this appears
- threaded-r Foundational decision that shaped the entire project strategy.