wahani / modules

Modules in R
https://cran.r-project.org/package=modules
Other
81 stars 3 forks source link

Why use `delayedAssign` in ModuleParent? #10

Closed aviralg closed 5 years ago

aviralg commented 5 years ago

I am trying to understand the implementation of modules.

Its not clear to me why delayedAssign is used instead of assign for defining depend, export, import, use, module and expose functions in ModuleParent

wahani commented 5 years ago

I made this decision when I started out with the project. I am also thinking about removing it because the 'feature' it introduces is of little to no practical relevance. However, it complicates the code and implementation. Just as a preamble.

When I started the project, my aim aim was to have a 'light-weight' package. Mostly because in the setup I was working in, package updates required more work than to swap a script file. Hence I tried to carry on some features of R packages: lazy load of data. What I ended up with, was lazy load of all objects in the import section. This had two implications: (1) package namespaces (of imports) are not loaded until the import is actually used (2) data was not loaded unless actually used (respecting the lazy load of an R package).

With the same motivation the 'local module namespace layer' you are referring to is constructed lazily. Also here, I do not think that using assign instead of delayedAssign has any practical relevance. At this point the 'modules' package is already loaded.

Feel free to continue asking or report back so we can close the issue.