benmarwick / rrtools

rrtools: Tools for Writing Reproducible Research in R
Other
668 stars 84 forks source link

`rrtools::use_compendium()` doesn't create an R folder. #150

Closed eliocamp closed 1 year ago

eliocamp commented 1 year ago

The rrtools::use_compendium() function creates a new project and a DESCRIPTION file, but not R folder. I think this is a bit confusing, especially for novices. In contrast, the New project -> R Package menu in RStudio creates an R folder with a sample R script. I think that's much more friendly to beginners as it self-documents where to stash the code.

Is there a particular reason why rrtools doesn't create this folder?

benmarwick commented 1 year ago

Yes, we've found that most people, beginners and more experienced researchers, are writing most of their R code in their Quarto markdown document (formerly R Markdown), or in R script files that they prefer to locate close to that markdown document, for example in the 'analysis' directory.

We observed it is not typical for researchers to write regular R functions (with documentation, examples, etc.) intended for reuse by others in their research compendium. So we set the default file structure to omit that R/ directory to avoid unused clutter.

Of course we give the option for that R/ folder to be included in the template, a user can run use_compendium(simple = FALSE) and it will be there.

eliocamp commented 1 year ago

Ok, thanks for the response. I guess I'm in the minority then; I do like to write my functions in package form and then load them with library(pkgname).

benmarwick commented 1 year ago

No worries at all! I'm always curious to see how people organise their code to share. Please do share you paper with me so I can take a closer look. A few years ago I published a few research papers with compendia using the style like yours, with fully defined and documented R functions using the package tooling.

I found it to be a lot of additional work and complexity for unclear benefits to me or the users of my code (so far I don't think anyone else has used those functions!). I guess other researchers are coming to similar conclusions about this which it is why it's so rare to see domain research papers accompanied by R packages. So that's why we altered the default file structure. Originally rrtools did give the user the R/ directory in their compendium.

Of course this approach is distinct from methods paper, where the functions are the main product for others to use. In that case I fully agree that the normal package structure is ideal, e.g. https://doi.org/10.1016/j.quageo.2021.101235

eliocamp commented 1 year ago

Here's one example: https://github.com/eliocamp/shceof

I find that writing the documentation helps me understand what the function does at the time of writing and, of course, when I need to read the help pages. It's also tidier than throwing everything in a long Rmarkdown setup chunk, which is already long with document-specific code.

benmarwick commented 1 year ago

Thank you, I really like the details in your readme, lots of good ideas in there!