How wch/r-source works
Project type & purpose
• R is an interpreted, functional programming language and runtime environment for statistics and graphics.
• It combines a C/Fortran core interpreter with a large standard library (“library/…”) of R‐level packages (stats, graphics, base, etc.), plus modules (X11, internet, lapack) and extensive tools.
Top-level components
a. Build & Configuration
– Autotools layer (configure, Makefile.in, etc.)
– m4 macros, etc/ and po/ for localization
– scripts/ for shell wrappers
b. Core Interpreter
– src/main: CLI front-end (Rmain.c), command–line parsing, startup
– src/main + src/appl + src/modules: expression parser, evaluator, memory manager, garbage collector
– include/: public & internal headers defining R’s C API
c. Math & Numerics
– src/nmath: standalone math functions (distributions, random variates)
– src/extra/blas & modules/lapack or system BLAS/LAPACK
d. Graphics
– library/grDevices & library/graphics & library/grid: R-level graphics packages
– src/extra/graphapp, modules/X11, Tcl/Tk front-ends, device back-ends (PDF, X11, Windows)
e. Standard Library (“library”)
– library/base, compiler, datasets, methods, parallel, stats, stats4, tcltk, tools, utils, translations
– Each is a loadable package (R‐level code + C stubs + documentation)
f. Extensions & Modules
– src/modules: dynamic modules (internet, lapack, X11)
– “Contributed packages” via CRAN (not in this tree but loaded at runtime)
g. Tools & Documentation
– tools/: Rd processing, package building, dynamic help
– doc/: manuals, HTML/CSS/JS for help pages
h. Tests
– tests/: unit and integration tests for core, graphics, embedding, packages
Relationships & data flows
– CLI/GUI front-ends → Parser/Evaluator
– Evaluator → Memory Manager (allocation/GC)
– Evaluator → Native primitives (C/Fortran functions in src/main, src/nmath, BLAS/LAPACK)
– Evaluator → Standard library packages (loaded via dynamic loader)
– Graphics functions → grDevices → device back-ends → display/file output
– Tools (Rd2HTML, Sweave) read doc/ and library man/ to produce documentation
– Build layer drives compilation of all components
Architectural patterns & design principles
• Layered architecture: front-end, evaluator, primitives, devices, library
• Plugin model: packages and modules loaded dynamically
• Autotools build: platform-agnostic configuration
• MVC‐like for graphics: high-level R graphics calls → graphics engine → device drivers