Programming and ‘R’

If someone had told me that within the first 2 months of starting a PhD I would have two written exams, I would have run in the opposite direction. If I’d been told that one of these assessments would be a programming exam that involved learning a new language called R, I would have run faster.

Before beginning my PhD, I had minimal programming experience. I’d taken a statistics module using RStudio, though I just used functions from a list. I’d never imagined that I would have to, let alone be able to, create my own functions to do whatever I wanted.

This seemed more exciting than daunting before myself and my course mates started. We jumped straight into making functions, which require an input, run through parameters outlined using the language we were learning and output an answer. At the beginning of the seventh hour of intense classes, myself and a friend were asked to create a for loop for a question we had got wrong in a mock. We looked at each other in confusion as we had no idea what that meant.

For those of you who don’t know what this is, as I didn’t, I would compare this blunder as the equivalent of the third week of an intensive baking course and not knowing what mixing with a wooden spoon was. This was my experience of programming after three weeks. It wasn’t for lack of trying, it was simply confusion and a complete deficit of knowledge; which, unsurprisingly, horrified the demonstrators. I was advised to attempt some basic questions on a handout and after three hours I was able to complete five – which should have taken far less than an hour. Nonetheless, I completed them.

Of course, I was still completely ignorant as to what a ‘for loop’ meant. I knew the format from a handout I had previously been given and had minor success manipulating it to create these functions I’d been tasked with. However, if I had to explain what they meant or what they did, I couldn’t. Not to overuse the baking reference, but it was as if I knew I had to mix all the ingredients together without understanding what each ingredient was.

‘For loops’ are just one of the many loops and tools used for creating functions, I have since utilised many of them but certainly not all. As I write this only days before the exam, I can honestly say that I finally understand what a for loop does – after dozens of hours of wanting to pull my hair out, an embarrassing number of frustrated tears and a single pass mark from five mock exams. I know that the purpose of the class was to give us the skills to create our own programs which would be useful during our research. Now, I get excited that I can write my own program to make the reverse compliment of a DNA sequence, or as my friend did with her newfound skills, print “I am amazing” multiple times to my screen.

As I head into the exam, I hope that I will be able to complete those elusive functions that have teased me for months, like the below function that my friend and I wrote recently without any guidance or help. Admittedly, we wrote it together and despite our persuasiveness we won’t be able to sit the exam together, but it was the first time we felt we had accomplished something. Overall, the main positive for me regardless of the outcome is the fact that I understand a for loop, and I still have some of my hair left.

Programming is another language…

Gabrielle is from New Zealand and is currently undertaking a PhD in Biosciences.