# Project directory organization: where does code output go?

I'm trying to build a project directory organization structure which follows best-practices. Adapting this structure, part of my project structure would look as follows:

``````myproject
myproject/code/r/main.r
myproject/report/main.tex
``````

Q: Where should I tell my R output to go though? Is there a generally acceptable best practice which is the least breakable, most modular, most intuitive, etc.?

I see a few options:

1. `myproject/code/r/`. In this case `main.tex` will include statements like `\includgraphics{../code/r/output.pdf}`. This seems clunky though. Should `main.tex` really "know" about `../code/r/`?
2. `myproject/code-output`. In this case `main.tex` will include something like `\includgraphics{../code-output/output.pdf}`. `main.r` would include statements like `pdf("../../code-output/output.pdf")`. Right now this is my preferred method. It seems logical for `main.r` to "put" it's output in a directory that is reasonable for `main.tex` to "see".
3. `myproject/report/img`. In this case `main.tex` will include something like `\includgraphics{./img/output.pdf}`. `main.r` would include statements like `pdf("../../report/img/output.pdf")`. I don't like this approach for the same reasons as "1." above: in this case, it doesn't seem like `main.r` should "know" about `\report\img`.

I'm not a programmer but may be doing a lot of this. So, I'm very curious how programmers think about this sort of stuff. All thoughts are welcome!

-

Is there a generally acceptable best practice

There is again no best practice. This is true for all of LaTeX, so please don't ask for best practices again ;-)

I'm not a programmer

If you work with R and TeX you are a programmer :-)

Generally I think all your suggestions are fine. Separating the document from data files is recommended because LaTeX likes to produce lots of auxiliary files. While there is the option to use `--output-directory` as mentioned in the post you linked to, many editors are not aware of this and place output files in the input/current directory by default. So the rule of thumb regarding LaTeX files is to use a dedicated directory for every document. If you want to compile several versions from more than one source, these should go into different output directories.

Regarding pictures and other data input files: (1) and (2) can theoretically cause problems because it is possible to disable reading files from parent directories (which might make sense in batch-processing environments that receive untrusted input). I usually choose a combination of (1) and (3) by having the data processing tool place its output in the same directory as the input (or similar), and then adding symbolic links to the data/picture files in the LaTeX directory. I think that approach combines the advantages of (1) and (3): the data processing tool doesn't need to know that its output is used in a TeX document, and the document doesn't need to know where the data comes from. So in your case I'd add a symlink `myproject/report/img/output.pdf` pointing to `../../code/r/output.pdf`.

-
@Phillip: Well, whatever. By "best practice" I'm just trying to find out what a good approach may be. Btw, your answer is very helpful. I like this set-up. I'll follow it. –  lowndrul Mar 2 '11 at 3:32
@Phillip: I'm trying what you suggested using shortcuts (not symlinks) in Windows and am having trouble. I posted a follow-up question How can I pass a shortcut to `\includegraphics`. –  lowndrul Mar 3 '11 at 2:38
@brian: I think if you want to follow my suggestion, you need symbolic links (which are supported by Windows btw). –  Philipp Mar 3 '11 at 13:07
@Phillip: Yes using `mklinks` from the command line in Windows and making sure that the link had a `.pdf` extension (since I'm using PdfLaTeX) was the trick. Everything works now. –  lowndrul Mar 3 '11 at 15:06