How rcppcore/rcpp works
Project type and purpose
• This is an open-source R package (“Rcpp”) that provides seamless integration between R and C++.
• It serves as both an R package (R code + registration) and a header-only C++ library (inst/include) to map R’s internal SEXP types to C++ classes, support “sugar,” “modules,” and “attributes.”
• It is distributed via CRAN/GitHub, built with R CMD INSTALL, and tested via tinytest+GitHub Actions+Docker.
File-structure analysis
• Top-level directories:
• R/ → R wrapper functions, registration, attribute handlers
• src/ → C++ source, Makevars, module initialization, API glue
• inst/include/ → Header-only C++ library, organized by component (Vector, sugar, stats, etc.)
• man/, vignettes/ → Documentation
• inst/examples/, inst/skeleton/ → Example code & code skeletons
• inst/tinytest/ → Unit tests (C++ & R)
• .github/, docker/ → CI/CD pipelines and Docker images
• Patterns:
• “Attributes” codegen: R/03_prompt.R etc. generate wrappers for C++ functions at install time.
• “Modules”: src/module.cpp + header inst/include/Rcpp/module
• “Sugar”: template-based lazy evaluation in inst/include/Rcpp/sugar
• Build scripts: src/Makevars(.win); Rcpp.package.skeleton.R; Dockerfiles for multiple R versions.
Key insights from README
• Single package exposing: Rcpp::wrap / Rcpp::as (conversion templates), Rcpp sugar, Rcpp modules, Rcpp attributes.
• Documentation delivered via ten PDF vignettes, extensive man pages, Rcpp book.
• Testing: tinytest harness, >1000 unit tests.
• CI: GitHub Actions (linux, macOS, ARM), Docker-based clean builds.