# Programming (useR! 2011)

August 17, 2011
By

(This article was first published on Why? » R, and kindly contributed to R-bloggers)

## Ray Brownrigg – Tips and Tricks for young R programmers

### Problem:

Calculate the distribution function of a bivariate Kolomogorov Smirnoff statistic. Essentially three loops. Basic exhaustive search is O(N^3). Fortran gives a single order of magnitude speed-up. Restructuring in R using a single loop is an order faster than fortran. Further improvements make the algorithm 3 times faster.

### Solutions

• Resolution of pdf graphs: specify width and height to suit eventual size.
• Local versions of standard functions: compare rank(x) with .Internal(rank(x, "min")).  Ditto with sort
• Vectorisation
• Curve: handy for finding errors

### F Schuster – Software design patterns in R

In Java software design patterns are everywhere. What about R?

### What is a design pattern?

A generalised, reusable and time test-test solution. Every pattern has a description of its general principle. A collection of patterns are organised into catalogues. Reusing proven concepts helps productivity.

R design pattern

• Factory method pattern. e.g. plotting program calls a function to get a symbol. The factor method makes the program independent of how the symbols are created.
• A function closure maintains the object state. You can have private functions within a closure.
• Map pattern – apply function in R
• Filter -
• compose concept and chain of responsibility

## Patrick Burns – Random input testing with R

Good talk, just found it hard to make notes. A closely related topic is fuzzy testing.

Please note that the notes/talks section of this post is merely my notes on the presentation. I may have made mistakes: these notes are not guaranteed to be correct. Unless explicitly stated, they represent neither my opinions nor the opinions of my employers. Any errors you can assume to be mine and not the speaker’s. I’m happy to correct any errors you may spot – just let me know!