Basic programming
For learning more about programming in R, I suggest that you check out:
- Advanced Programming in R
- A “web book” (in html) called “Ramarrow” (the Italian name for Green Lizard/Smaragdeichse Lacerta spec.) on “R for Developers”. A technical and example-rich introduction to programming with R, incl. S3/S4 classes, package production, debugging and alike.
- Ben Bolker’s Ecological models and data with R
- Pitfalls of the R language
- For Germans - Ligges, U. (2008) Programmieren mit R. Springer. is a great book!
Understanding the R environment
- http://blog.obeautifulcode.com/R/How-R-Searches-And-Finds-Stuff/
Efficient R code
In a language that is compiled, such as C++, the compiler usually optimizes your code during the compilation process. R is not compiled, but interpreted. That means that one two options to write some code that produce the same output may have dramatically different runtimes.
Basic laws are:
- Vectorize everything / i.e. avoid for loops
- Avoid reasignment or copying of large variables
- Prefer using in-built functions, particularly if they are compiled
For a more in-depth discussion, see here
If you have severe runtime problems, consider paralellization and or moving code to c/c++.
OO programming in R
Parallelization
Useful links:
- parallel-basics
- R-parallel-package-example
- Getting Started with doParallel and foreach
- Using The foreach Package
- R parallel WIKI
- Easier Parallel Computing in R with snowfall and sfCluster
- Developing parallel programs using snowfall
- A Survey of R Software for Parallel Computing