0

I apologise in advance for perhaps asking a very obvious or uninformed question, but considering that I have used quite a bit of time trying to solve it now without any apparent solution, I venture to post it anyways:

I've worked on a project now for some time that have produced an .R file with around 1300 lines of code, which starts to get troublesome to work with. I am certain that there are better ways of structuring code than just having it line after line in such a manner. The main purpose of the programme is to load some data in, transform it in various ways and then write the result out as .csv files.

My question is then: Where can I find examples of or learn how to structure R code that becomes unruly in a single file?

One solutions I have thought of is to use a structure with one main file with several source calls to other files. Another would perhaps be to make a package.

avriis
  • 1,581
  • 4
  • 17
  • 31
  • 2
    Here you find some advice for code styling: https://google.github.io/styleguide/Rguide.xml – Martin Schmelzer Jan 18 '16 at 10:37
  • 1
    First step: break-up your code into functions. Then document the functions. You could then consider putting the code into a package (a basic package is not difficult to create) to better facilitate documentation and testing. – Roland Jan 18 '16 at 10:43
  • This question has been asked & answered before, see: http://stackoverflow.com/questions/1429907/workflow-for-statistical-analysis-and-report-writing, http://stats.stackexchange.com/questions/2910/how-to-efficiently-manage-a-statistical-analysis-project/ http://www.r-statistics.com/2010/09/managing-a-statistical-analysis-project-guidelines-and-best-practices/ http://nicercode.github.io/blog/2013-04-05-projects/ http://stackoverflow.com/questions/1266279/how-to-organize-large-r-programs – Ben Jan 18 '16 at 10:50

0 Answers0