Sherlock
Sherlock

Reputation: 5627

One class per file in R

R beginner with a two part question -

  1. I like the one class per file 'rule' in 'other' languages - is this a common practise in R also ?

  2. How would I go about doing this in R ? From the documentation I've read so far, I would have to create a package and use 'require'. However, will I need to write man pages and documentation for each package ? (One file may contain a very small class that I don't really want to document). Are there any alternative ways of doing this ?

Many thanks

Upvotes: 0

Views: 105

Answers (1)

Ari B. Friedman
Ari B. Friedman

Reputation: 72741

Three options for you:

  1. ProjectTemplate may have functionality that would let you load all source scripts in a given directory automatically.

  2. You can write a simple script that does it yourself by source()ing the output of dir(). taRifx::readdir does something similar to load all data files in a directory.

  3. Likely the best answer: put all your functions into a package, even if you don't release it to CRAN. All .R files in the R directory automatically become part of the package when you build it. Bonus: documentation becomes easier as well (use roxygen2).

Upvotes: 3

Related Questions