Code for r programs