Employment of Modules: Structures and constructions

From the previous chapter, the guide thoroughly explains how to import R packages and scripts / folders using box::use(), the fundamentals of {box} package, and why it is such convenient in having more control on how you attach the namespace, between bulky and granular imports, and how {box} absolves namespace conflicts in the current environment.

In this chapter, we will dive deeper into the composability, organization, and reusability of modules using {box}. By structuring your code into reusable modules, you can make your R projects more manageable, scalable, and long-term maintainable.


Recall on Module Basics

In {box}, a module is simply between an imported R package, R scripts, or a folder that contains an R script that encapsulates related functions, variables, and objects, forming a cohesive unit of functionality. Think of a module as a container of reusable code, and is containing a namespace, similar to how Python packages work. This design encompasses what module system for R should be, where you organize your code into logically separated units, making it easy to maintain and reuse across different projects. It’s not like R doesn’t have this, it just lacks the ergonomics on composability, reusability, and organization.