What's the difference between box::
and import::
?
#315
-
See https://cran.r-project.org/web/packages/import/vignettes/import.html. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I’ve been meaning to write a comparison article but doing this in a fair way is hard because (a) I am obviously biased and (b) I admittedly don’t know ‘import’ nearly as well as ‘box’. Having said that, it is my conviction that the module system implemented by ‘box’ is strictly superior to that implemented by ‘import’. Furthermore, as far as I am aware, the functionality provided by ‘box’ is a superset of the functionality provided by ‘import’: it does everything1 ‘import’ does, plus more. But let’s start at the beginning. ‘box’ and ‘import’ have a large overlap in functionality and aim to solve some of the same problems, but I think the overarching aims differ:
Over time, the two packages have converged in functionality. In particular, ‘import’ has gained the ability to load code from scripts rather than packages, which is similar to (but more limited in scope than) the module system from ‘box’. And ‘box’ has gained the ability to import packages in addition to modules because I realised that my stated aim of replacing the existing package system was too ambitious. So what does ‘box’ provide that ‘import’ does not provide?
(Note that this is a non-exhaustive list; I do want to keep it short.) Here they are in more detail: Global module library‘box’ knows two types of modules: project-local modules and global modules. Project-local modules are located in a subfolder of the current project. Global modules are located in one or more a central installation locations, akin to the R package library (that’s why you can use an R package in your code without having to reinstall it for each project). The R package library paths are configured via Relative imports that actually workSupporting project-local modules — and in particular hierarchical, nested modules — requires that these modules can be found by the import mechanism. ‘box’ does a lot of work behind the scenes to ensure that First, here is the folder structure:
And here is the (working) ‘box’ implementation:
|
Beta Was this translation helpful? Give feedback.
I’ve been meaning to write a comparison article but doing this in a fair way is hard because (a) I am obviously biased and (b) I admittedly don’t know ‘import’ nearly as well as ‘box’. Having said that, it is my conviction that the module system implemented by ‘box’ is strictly superior to that implemented by ‘import’. Furthermore, as far as I am aware, the functionality provided by ‘box’ is a superset of the functionality provided by ‘import’: it does everything1 ‘import’ does, plus more.
But let’s start at the beginning. ‘box’ and ‘import’ have a large overlap in functionality and aim to solve some of the same problems, but I think the overarching aims differ:
The primary aim of ‘impo…