1

Is there any code self-documenting system for R?

I think writing documentation is a very important part of any statistical analysis. There are always important details in your code or the steps of data cleaning that are not reflected in the final analysis report. I wonder whether there is any efficient self-documenting system (or approach) in R that can help me documenting my codes including my comments o my codes with structure files explaining the structure of the datasets (or tables) used in my code?

Beyond using Sweave or knitr in R, is there any other way of doing that?

Sam
  • 4,357
  • 6
  • 36
  • 60

3 Answers3

4

I'd suggest bundling up your code and data sets in an R package. There's a steep learning curve the first time you do it, but if you're at the point where you're asking, "how can I better manage this code documentation thing", you're likely ready to take the plunge.

Plus, doesn't the idea of typing ?myOwnFunction or ?myOwnDataset, and having the appropriate help file pop up (just as it does when you do ?mean or ?iris) sound appealing?

Josh O'Brien
  • 159,210
  • 26
  • 366
  • 455
  • It does. The missing part that I had been looking for was to figure out how to document dataset cleaning steps. Ari's answer seems to be a solution. Thank you again Josh. – Sam Aug 01 '12 at 01:38
  • And, to take it one step further, if you have functions that might be of general use, contribute them back to the community in a CRAN package. I find the process of doing so (and the debugging, feature-adding, and generalizing that goes with it) often makes the functions more useful to my own projects as well. – Ari B. Friedman Aug 01 '12 at 01:39
3

You might try writing your code as a Sweave or kntr file, which contains LaTeX text along with R code. This process produces a pdf of your text, including your code, and executes your code.

Charlie
  • 2,801
  • 3
  • 26
  • 27
  • Hey Charlie, Thanks for your answer. I actually use Sweave and knitr all the times in my reports, I wanted to see whether there is any other way for that. – Sam Aug 01 '12 at 01:04
  • @Sepehr: What more do you need? – David Robinson Aug 01 '12 at 01:28
  • Hi @DavidRobinson: The missing part was to figure out how to document the data cleaning steps and Ari's answer seems to be a solution. – Sam Aug 01 '12 at 01:40
1

If you choose to organise your analysis as package, you can use roxygen2 for documentation of your code and data.

Karsten W.
  • 17,826
  • 11
  • 69
  • 103