AnIntro2RTutorial

An Introduction to R Tutorial

This tutorial can be used by students to get working with R using RStudio. It is intended to be used by someone that has not used R before.

I use this material for both my Ecologia Numérica and my Modelação Ecológica at FCUL courses 1.

All the relevant material is available here at the corresponding github repository.

Quick start

To start using this tutorial right away download 2 the contents of the corresponding github repository. At a bare minimum, you should first look at the slides at AQuikIntro2RandRStudioInQuarto.html available at Rpubs 3

Then, download (at a bare minimum) these three files:

Then open the PDF and work over it from the top, running the code examples in RStudio. Modify the code as you go, so you can experiment and see how R behaves.

Dynamic reports

These days I tend to work using dynamic reports made in Quarto.

"Artwork from "Hello, Quarto" keynote by Julia Lowndes and Mine Çetinkaya-Rundel, presented at RStudio Conference 2022. Illustrated by Allison Horst."

This makes the entire analysis workflow, from reading the data and cleaning it all the way to reporting the results from one’s analysis, integrated and fully reproducible.

Working with dynamic reports is a good skill to have if you are a biology student, and so, if you are a student of one of my courses at FCUL, I will also show you in class how those work. In fact, this will be a highly transferable skill that will be useful in many working environments beyond the analysis of biological/ecological data. Learning from scratch how to work with dynamic reports might be hard, but starting from a template helps. If you want a template for creating dynamic reports, I created one for you here.

My suggestion is that you start by creating your own dynamic report, which you then use as a basis to work with the code and experiment variations of the code in this tutorial.

Tips before you go

Keep all your code properly commented: what seems obvious to you today might not be obvious to the “you” next week or next month. Coding is a collaborative experience, even if between you and your future self (This quote, or something similar, might be from Hadley Hickam).

If you are new to R in general, the R cheat sheets are great resources, and I recommend to begin with downloading these:

If you want to learn R interactively from the command line, you might want to try package Swirl. Your own R tutor at your fingertips. Try it!

Additional online resources

Below I also provide a list of additional free online resources that you might want to consider as additional R learning resources. Some of these resources are not about R itself, but about some relevant aspect of statistics that uses R. If you happen to know about a good resource to add to the list below, send me the link and I’ll add it below.

This is a non-exhaustive, non-comprehensive and quite random list of R (and related) resources that I found useful at some point. They might (but will not necessarily) be ecologically oriented. Feel free to explore at your own risk. No real order in the list I am afraid.

General R

R for statistics and data science

R for ecology

R for (medical) biostatistics

R as a GIS

R6 (aka Rather Random Restrict-Realm R Resources)

Footnotes

  1. If you are a student in one of those courses the tutorial section Final tasks is only intended to be completed for those in Modelação Ecológica

  2. If you are new to RStudio this presentation can be helpful in getting you started. If you are a student of one of my courses at FCUL, this presentation will be delivered to you in class. 

  3. This was made for biology students. I assume you don’t know your way around github. If you do, feel free to clone the repository and provide comments and raise issues that way. If you do not know github, ignore this! 

  4. The file TAMsIntro2RviaRStudioTutorial.pdf was generated by compiling TAMsIntro2RviaRStudioTutorial.qmd, a Quarto dynamic report. In the github repository there are corresponding TAMsIntro2RviaRStudioTutorial.html and TAMsIntro2RviaRStudioTutorial.docx files if you prefer to work from these formats. Or, you can compile them yourself from the .qmd as a test to see your work in different output styles.