Marie-Hélène Burle
             -----------
email msb2@sfu.ca  twitter @MHBurle  github prosoitos
September 05, 2018

R workshop for the International Ornithological Congress 2018
Better practices in R,
no more copy-paste, no more loops

Table of Contents

Most of us biologists do not learn R properly: we do not have a computing science background, we do not necessarily have access to R courses, and when we do, these seldom make use of the latest tools. So, for the most part, we learn R as we go and we become good at problem solving. But do we ever become good at writing good R code?

This workshop focuses on two sets of considerations important for writing better code:

Program

Portability, reproducibility, and readability

Code that is portable, reproducible, and readable is critical when collaborating on projects. At the start of this workshop, we will briefly go over:

  • Self-contained projects for portability (as described by Jenny Bryan),
  • Clean sessions for reproducibility,
  • Standard formatting for better readability (as suggested by Hadley Wickham).

The workshop material can be found here.

Functional programming

What do you do when you need to apply the same treatment to multiple datasets or multiple variables within a dataset?

Imagine that you have a banding data file and you just wrote some code to transform the raw tarsus length data in a format suitable to analysis. Now, you would like to apply the same code to other variables in your banding data.
Or you wrangled the data in a file by a series of steps. But you have a whole folder full of similar files…

How do you do this?

Copying and pasting code, besides being tedious, is a form of hard coding and is thus prone to errors. Loops provide a much better approach, but they require a lot of code and still involve some level of repetition. They are also hard to read and the goal of your code might not be obvious right away when you go back to it or you give it to someone else. Functional programming is a coding paradigm in which functions are applied to several elements in a vectorized fashion. This makes for compact code that is much clearer and takes advantage of the vector-based nature of R. The purrr package (part of the core tidyverse) provides a collection of efficient and consistent tools to functional programming in R.

This section constitutes the main part of the workshop. In it, we will focus on:

  • A very brief introduction to functional programming,
  • How to apply functions to several elements of a list/vector with some of the main purrr functions,

The workshop material can be found here.

Bonus: magrittr less used pipes

A detour to a few of the less used pipes of the magrittr package which are so useful when playing in the tidyverse.

The workshop material can be found here.

Logistical considerations

Target audience

  • Intermediate R users comfortable with basic data manipulation and simple functions,
  • Advanced users familiar with functional programming using the family of the apply() functions and interested in discovering the "purrring" way.

Where and when?

Date: Thursday 23
Time: 8pm-10pm
Place: Vancouver Convention Centre, Rooms 116 & 117

No fee nor registration

There is no fee nor registration for this event. Simply join us with your laptop ready for the workshop (see below).

Software requirements

In order to make the best of this workshop, please bring a laptop with the following installed:

  • the latest R release (3.5.1 Feather Spray),
  • the latest version of the tidyverse package,
  • and if you usually run R in RStudio, please also make sure to have the latest RStudio.

No data file is needed for this workshop.


About myself:
I am a PhD candidate in the Centre for Wildlife Ecology at Simon Fraser University,
an R Data Peer at the Research Commons,
a Graduate Writing Facilitator at the Student Learning Commons,
an admin of the Scientific Programming Study Group,
and a certified Software Carpentry and Data Carpentry instructor.