Style and workflow

Statistical programmers can think of R code—like other languages—as being dysfunctional, functional but awkward, or graceful. Graceful code is clear and readable, which helps prevent errors. Here are a few tips on writing graceful R code:

  • Filenames should end in .R and be meaningful.
  • Variable names should be short. If necessary, use a period to delineate multiword variable names (for example, my.variable).
  • Keep every line short. R will not terminate a command until all parentheses are closed, so feel free to wrap commands across lines for brevity.
  • Use spaces before and after assignment, after commas, and around parentheses and operators (such as +) for readability.
  • Use the left arrow with hyphen (<-) for assignment, never the single equals sign.

For more details on writing good R code, refer to the guide at http://google-styleguide.googlecode.com/svn/trunk/Rguide.xml. Again, though R can be used interactively from within the terminal, it is best practice to develop code within an IDE, such as RStudio, so that it can be saved, changed, and rerun. Additionally, building version controls and persistence into your code by storing it on GitHub may be important, especially if you find yourself working in a group environment. Finally, many users will find the creation of projects useful—the RStudio documentation offers useful tips on this topic.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.239.226