HenrikBengtsson / Wishlist-for-R

Features and tweaks to R that I and others would love to see - feel free to add yours!
https://github.com/HenrikBengtsson/Wishlist-for-R/issues
GNU Lesser General Public License v3.0
134 stars 4 forks source link

Allow subdirectories in the R directory (R packages) #128

Open krzjoa opened 3 years ago

krzjoa commented 3 years ago

When creating a new R package, there is no possibility to organize the scripts in categorical subfolders. I guess there was an assumption that every R package should be modular and atomic, so it'll never be bigger than just a couple of scripts.

However, projects such as e.g. torch or parsnip show that without subdirectories it can get a little bit messy. In the src folder, unlike the R directory, it's possible to use subfolders (see an example: rcpp-headers-subdirs).

In my opinion, it would make package development more convenient in many cases.

karoliskoncevicius commented 3 years ago

There is a some reason subdirectories are not allowed. The manual states that only special-purpose "unix/" and "windows/" subdirectories are allowed under R/ , presumedly for files that are specific to windows or unix systems.

Also, when discussing this matter, a well known R developer Hadley states here that he has no trouble managing big numbers of files in his packages.

A personal solution might be using directories while developing and then flattening them when building a package. This is also offered as a solution in the r-devel thread on the same topic.

krzjoa commented 3 years ago

Yes, I forgot to mention about the possible OS-related subdirectories. But still, it'd be not so hard to keep unix/ and windows/ subdirs reserved for the special purposes.

I know that there is no absolute measure to state that "there is to many/not so many files in this directory" and I stand by my opinion.

nfultz commented 3 years ago

For me, there's little benefit (but also little harm) to allowing subdirectories if, at the end of the day, all the files are simply concatenated together - eg https://github.com/wch/r-source/blob/780021752eb83a71e2198019acf069ba8741103b/src/library/tools/R/admin.R#L299-L314

If, somehow, subdirectories could automatically be separately namespaced, the tools package itself would be a good candidate for refactoring - it currently uses a few nested, thousand-line closures to achieve some isolation, but that can make it hard to debug or figure out what it's actually doing.

krzjoa commented 3 years ago

From my perspective, as the multiple files are better than one big file, so are multiple subdirectories better than one big directory. It would really make difference.

Sub-namespaces is another interesting topic. I didn't write about it because for now I have no idea, how should it be implemented.

mlell commented 3 years ago

@krzjoa the package box provides modules and sub-modules. The barrier to start a module is much lower than to start a package, but it lacks the versioning and distribution mechanisms of R packages

krzjoa commented 3 years ago

I know the box package, but the goal of this proposal is to organize scripts in packages rather than create submodules.