Description
We can have namespaces where subfolders see functions from parent folders, useful for scoping the code or preparing for a split into several packages. It would be just for dev, because whatever works when scoped works when the namespaces are flattened as long as there is no name collision, and we can check for this.
I think the flattening is not too hard because when in development we actually don't use 'sysdata.rda' because when we reach .onLoad()
it's already loaded, so we just populate it, and then override with the new values, so we already have a double process.
To do this right we need basically a tree of namespaces, and we need some imports env for each namespace for the functions of the given package. At least if we want to do more flexible scoping.
Simple scoping works like this :
- file in R are accessible anywhere
- files from a folder are accessible from subfolder
So we end up putting all general utils in R or in the main folder, and specific functions below.
But it doesn't handle the common use case of having a complex function with private helpers. in that case we want the top function to be bound above the others, but to have access to its helpers, so it beeds to have an environment below.
This case can be handled by convention, by having foo.R
next to foo-helpers.R
. But this is is not quite enough!
What if I have a family of functions that share helpers ?
I think we could have a tag "@ needs" or "@ helpers" or "@ scopes" or "@ importDir" that would be ignored by roxygen2 (we'd build an empty tag) and parsed by us, and there a function would declare what it needs. so fun1 one needs helper1 and helper2, that are located in "fun-helpers" folder, so we have a "<mypkg/fun-helpers>" namespace (no imports env needed for it) and with the 2 helpers, by default from the structure, and fun
has its own namespace importing them.