wahani / modules

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

Feature idea: let `use` search through a file search path #33

Closed mmuurr closed 2 years ago

mmuurr commented 3 years ago

In the case where use is passed a filename (or directory), can that file be detected as the first hit on a file search path? It'd be easy-enough to maintain such a set of path roots via an options().

For example options()$modules.filesearchpath and use the UNIX-y ':' separator in a single string for multiple paths in which to search. (This is a nice alternative to it being a vector of search paths, since this way that value could potentially be set as a shell environment variable, outside of R, though it could also be set as part of .Rprofile or various other ways, so, really any option works.)

wahani commented 3 years ago

Sounds like a nice feature. Some thoughts:

Do you have a specific use case in mind so I can better understand why a package may not be the goto vessel?

mmuurr commented 3 years ago

I've been spending a lot of time dropping R6 classes into modules, one class per module (more or less). One package to hold all the class definitions gets unwieldy, and one package per class is overkill, so really I've just been experimenting with different processes to find a balance between the two. This relates to #34, as various classes want to make use of each other (but again, only at runtime).

Outside of that, I can still see a potential benefit during development, where perhaps there is a shared directory of modules (e.g. a network-shared drive) and when one person is developing may want to insert a local directory at the head of that path. Then in the local directory, only those files pertaining to the current coding exercise would be needed, while the remaining files would be found by use as it moved on to the later directories in the path list.

But then again, it's not hard during local development to just clone a directory and do everything locally, so 🤷‍♂️ .

wahani commented 3 years ago

@mmuurr

I've just commited a draft for this. You may test this with:

devtools::install_github("wahani/modules", "use-path-modules")

I haven't even started to write tests, so no clue if this works properly. Here you now can specify the path using

first match wins. If the path contains several files of the same name in different folders ('~/R/modules:~/R/modules1'), first match wins. It should also be possible to use a folder, e.g. by referencing 'folder' when '~/R/modules/folder' exists.

Feedback is welcome.

wahani commented 2 years ago

Closed because inactive.