24.8 Other techniques

Being able to write fast R code is part of being a good R programmer. Beyond the specific hints in this chapter, if you want to write fast R code, you’ll need to improve your general programming skills. Some ways to do this are to:

  • Read R blogs to see what performance problems other people have struggled with, and how they have made their code faster.

  • Read other R programming books, like The Art of R Programming (Matloff 2011) or Patrick Burns’ R Inferno to learn about common traps.

  • Take an algorithms and data structure course to learn some well known ways of tackling certain classes of problems. I have heard good things about Princeton’s Algorithms course offered on Coursera.

  • Learn how to parallelise your code. Two places to start are Parallel R (McCallum and Weston 2011) and Parallel Computing for Data Science (Matloff 2015).

  • Read general books about optimisation like Mature optimisation (Bueno 2013) or the Pragmatic Programmer (Hunt and Thomas 1990).

You can also reach out to the community for help. StackOverflow can be a useful resource. You’ll need to put some effort into creating an easily digestible example that also captures the salient features of your problem. If your example is too complex, few people will have the time and motivation to attempt a solution. If it’s too simple, you’ll get answers that solve the toy problem but not the real problem. If you also try to answer questions on StackOverflow, you’ll quickly get a feel for what makes a good question.

References

Bueno, Carlos. 2013. Mature Optimization Handbook. http://carlos.bueno.org/optimization/.

Hunt, Andrew, and David Thomas. 1990. The Pragmatic Programmer. Addison Wesley.

Matloff, Norman. 2011. The Art of R Programming. No Starch Press.

Matloff, Norman. 2015. Parallel Computing for Data Science. Chapman & Hall/CRC. http://amzn.com/1466587016.

McCallum, Q. Ethan, and Steve Weston. 2011. Parallel R. O’Reilly. http://amzn.com/B005Z29QT4.