3

I am planning to write a substantially big program in R for the first time. Following my usual procedure, I have designed around 15 classes, which are distributed in 5 components. As I see it, each class (definition and associated methods) should be in each own file and each component have its own sub-directory. The desired structure is thus:

-R
 -component_0
   -classA
   -classB
 -component_1
   -classC
   -classD

Initially I created an empty project(using RStudio), but when I tried to use roxygen I realized that a package structure was necessary. Upon creating a package I was struck by its inability to support sub-directories.

I realize that developing my project as a package is essential, especially because I'd like seeing it in CRAN. But destroying my tree structure is something I definitely want to avoid. As I imagine it, the documentation should also have the same structure.

Can someone explain why this restriction exists? Is there any way to avoid it and accomplish what is self-explanatory in most computer languages, like C++?

Also, note that I've assigned a class to a file, rather than a function, which is the common practice. This seems to me the best option, since I've designed object-oriented software. Any comments upon that?

blindeyes
  • 409
  • 3
  • 13
  • You will find the answers for most of your questions here: https://stackoverflow.com/a/14905225/4468078 – R Yoda Aug 26 '17 at 16:54

1 Answers1

1

I have all R-files in the /R folder. There, I use file names of the form

  • component_0-classA.R
  • component_0-classB.R
  • component_1-classC.R
  • component_1-classD.R

Not really what you are looking for, but I think this is working well (at least for me).

Have a look here

Community
  • 1
  • 1
Christoph
  • 6,841
  • 4
  • 37
  • 89
  • 1
    I see, I was aware of this solution, which is far from attractive to me. I suppose I should compromise, but how this restriction came up and the purpose it serves will bother me for a while. – blindeyes Oct 21 '16 at 16:56
  • If everything is clear to you and the answer was helpful, it would be great if you up-vote and mark it as solved. Depending on your problem: if component_0 and _1 are big enough you could also create 2 packages and a top-level package using the two... – Christoph Oct 21 '16 at 17:08
  • The i was helpful, but I'd certainly appreciate other practices (well, if they exist) and a justification of this restriction. Your last proposal was really interesting, are you familiar with any project in Github that employs this technique? I'm afraid it could get too complicated for a newbie to develop a nested package, seeing an example would be really helpful. – blindeyes Oct 21 '16 at 17:25
  • If you have two packages, you can work with `depends` or `imports` argument in the `DESCRIPTION` file so that the top-level package knows about them. See [here](http://stackoverflow.com/questions/8637993/better-explanation-of-when-to-use-imports-depends). My experience is: start as simple as possible, in your case put all your classes in one package in the `/R` folder. – Christoph Oct 21 '16 at 17:33