Box: Placing module system into R

Definitive Guide 2nd Edition

Authors

Joshua Marie

John Riz Bagnol

Preface

Welcome to the definitive guide to module system in R using {box}!

You might have wanted another way to import R packages, or just simply sought better ways to write organized and composable R codes, welcome aboard! This book guides you to the re-imagination of how module system in R should have done. This book introduces you the package called {box} (initially started as a {modules} package) by Konrad Rudolph, and a Rust package with a thin CLI wrapper called {carrier} that helps you manage your {box} modules as if you are working with R packages.

What You’ll Find Here

R, especially its users, might have suffered from writing and managing huge R codebases, simply because there’s no clean way to manage such complex pipelines. Do not fret, this problem will potentially cease to exists, as {box} package provides closely equivalent module system to other programming languages like Python, C#, and more.

There are many ways to manage R codes, and most solutions out there are subjective. Even though they are subjective, none of the solution hits the level of ergonomicity to actually write and compose reusable R codes. Hence, this definitive guide is written, and what you’ll find here is the following:

  • Alternative approach to import R codes (i.e. R packages, modules)
  • Modern approaches to compose and organize R codes
  • Step-by-step tutorials for using {box} package
  • Best practices for maintainable R code
  • The deterministic introduction of {carrier} Rust package

Why this book

There might have handful of books that actually teaches you to correctly import reusable codes, as well to write reusable, composable, and modular R codes (well, R packages exists). Most of the books teaches you about R, particularly across different fields, but little to no books explains one of the best practices to write and import reusable and composable R code. Most of the books use library() and sometimes through source() (it is bad as a way to import your code but not when you want to execute the whole script), thus you won’t certainly find similar book that teaches modular codes.

Consequently, R offers various ways to organize R codes, but {box} package offers an ergonomic modern approaches to module system that may significantly improve your R development workflows. This book bridges the gap between basic R programming and professional-grade code organization.

How to Use This Guide

The content is structured progressively, building from foundational concepts to deep applications. For the best learning experience:

  1. Start with the introduction to understand the core concepts.
  2. Learning the fundamentals of import system with {box} package.
  3. Learning the structures and constructions of reusability of modules, treating them like R packages, and supplied with documentation
  4. Learning unit testing the modules

Contributing

Contributions are welcome! If you have suggestions or improvements, please open an issue or submit a pull request on the GitHub repository.

License

This book is licensed under the Creative Commons Attribution 4.0 International License (CC BY 4.0). See the LICENSE file for details.

Credits

This book was written by Joshua Marie and co-authored by John Riz Bagnol.

Special thanks to:

  • Konrad Rudolph for creating and maintaining the box package
  • The R community for their continued support and feedback

The book is built with Quarto, hosted on GitHub Pages.