wahani / modules

Modules in R

Home Page:https://cran.r-project.org/package=modules

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

mmuurr opened this issue · comments

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.)

Sounds like a nice feature. Some thoughts:

  • Conceptually we are entering the space of packages. They already support what you want and have obvious benefits.
  • How do you make those modules discoverable? I guess we can provide a function, listing all modules found in the path.
  • How do you make those modules sharable? Your code will rely on some modules only available on a specific system. modules also do not have versions. Even if you are just keeping your machine at work and your laptop at home in sync, that would be much easier and more reliable with a package.

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

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 🤷‍♂️ .

@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

  • the option 'modulesPath'
  • the environment variable 'MODULES_PATH'
  • or live with the default '~/R/modules'

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.

Closed because inactive.