A simpler, faster, and lighter-weight implementation of encapsulated object-oriented programming for R.
R6 is an R package that implements encapsulated object-oriented programming, providing a simpler, faster, and lighter-weight alternative to R's built-in reference classes. It allows developers to create objects with reference semantics, supporting features like inheritance across packages and public/private members. The package addresses the need for a modern, efficient object system in R without the complexity of S4-based solutions.
R developers and data scientists who need to implement object-oriented programming patterns, such as creating reusable classes with encapsulation, inheritance, and reference semantics in their R projects.
Developers choose R6 over alternatives because it offers a clean, performant, and dependency-free implementation of object-oriented programming, with cross-package inheritance and no reliance on the S4 system, making it easier to maintain and extend.
Encapsulated object-oriented programming for R
Objects have reference semantics, allowing modifications to be shared across references, which is essential for stateful applications like mutable data structures.
Supports clean inheritance across different R packages, unlike reference classes, facilitating modular code reuse and better package design.
Includes public and private members for data hiding and encapsulation, as demonstrated in the Introduction article, improving code maintainability.
Designed to be faster and lighter-weight than R's built-in reference classes, with performance tests showing speed and memory benefits.
Built independently of the S4 system, avoiding the need for the methods package and reducing installation and runtime overhead.
R6 supports only single inheritance, lacking features like multiple inheritance or mixins that are available in more complex OOP systems, limiting design flexibility.
Debugging R6 objects can be challenging due to reference semantics and method binding, as acknowledged in the dedicated debugging article, requiring extra care.
Compared to established systems like S3 or S4, R6 has a smaller ecosystem of third-party tools, libraries, and community resources, which can slow adoption.
Developers accustomed to base R's functional style or S3/S4 may find R6's classical OOP approach initially unfamiliar, increasing onboarding time.
Tools to make an R developer's life easier
Static Code Analysis for R
renv: Project environments for R.
Write reusable, composable and modular R code
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.