If you’re new to R, this “pre-vignette” tutorial serves as an
introduction to using evolved. It was largely inspired by
the first tutorials in EEB 485 and EEB 391/516 (Population and Community
Ecology & Evolutionary processes and Macroevolution), but it is
extended and modified to work in our context. This document is meant to
serve as a first contact with the tools that will be of major importance
in our vignettes with evovled. Nothing related to this
tutorial is required to use the R package, but we will be using all the
tools explained here, so please make sure you have completed it before
then (or to be genrlly familiar with R).
This tutorial will be somewhat long, and if this is your first time using R, it will also be a bit confusing. This is because a reasonable part of what you will see here is pretty abstract. We ask you to trust the learning process and keep reading until the end. We highly encourage you to reach out to other peers more knowledgeable in R, if needed. We know that different folks come with very different levels of comfort with R – which means you will learn a lot with your colleagues, however comfortable you may currently be with R.
R is (1) an open source software, (2) a programming language, and (3) a programming environment. The first one means it is a computer program you can freely download, use, or modify to your own needs. The second means it is a language that allows humans and machines to communicate. The third means it gives you everything you need to create your own programs under a specific language. Scientists, especially in the biological sciences, widely use R to run simulations and analyze their datasets, so we will do this too.
If you’re using your own computer and have not yet installed R, you can download and install it for free by pasting this in your web browser:
After you download it, install it as you would do with any other program – the installer program will direct you though the major steps. When you open R, you should see something close to Figure 1.
Please download and install R before progressing to install RStudio.
Example of recently-opened R on an Apple computer. The interface looks slightly different on a Windows computer, but the main features are the same. Note that depending on the details, you may or may not see the same warnings and errors as the screenshot.
RStudio is a development environment for R. As a very coarse
simplification, you can think of RStudio as a complement to R that makes
some tasks easier – a “shell” enveloping R that makes some
communications between you and R easier. However, many would say that
RStudio is not much of a helpful resource at all. If you never worked
with R before, you are encouraged to try both RStudio and just “plain” R
separately and make your own conclusion as to which makes you more
comfortable. You are not required to use RStudio to use
evolved, but you can use it if you think it will help your
learning process (you are required to use R, though).
Here in this class we will use programming as a learning tool, but programming is also a skill that will develop your quantitative ability and will make you a better scientist. If you really want to train this skill and get really good at it, we highly recommend that at some point of your career, you get used to programming just with R – and you are invited to use this class as one opportunity to do that. However, if your intention is to use R only occasionally, it might be worth jumping straight to RStudio, at the cost of being limited by a series of details and constraints that RStudio has.
If you need RStudio for your personal machine, you can download and install it for free by pasting this in your web browser:
After you download it, install as you would do with any other program – the installer program will direct you though the major steps.
If you intend to use RStudio, please download and install it before progressing to install RMarkdown. We will cover RMarkdown later in this tutorial.
When you start R, you should see something like figure 1. If you start RStudio instead, it will open R inside of the RStudio environment, and should look like figure 2.
Example of recently-opened Rstudio. Note that the appearance of RStudio is customizable, so your interface might not look the same as the RStudio your instructors or your fellow students have
Just looking at figures 1 and 2, it is easy to see that RStudio gives a lot more information. We will briefly walk through the items shown in figure 2 to familiarize you with each quadrant in the RStudio environment. Note that in both figures we are not showing the upper part of the screen (containing the tabs “File”, “Edit”, “Code”, “View”, etc.), but sometimes you will use those options too.
Upper-left: The script. This is where you view, edit, and save text files, including R scripts (.R files) and RMarkdown (.Rmd) files. You will use this quadrant the most during your learning activities.
Lower-left: the console (a.k.a terminal, a.k.a. command line). This is where lines of script get processed and computed. Here, you can see what code was actually input and run, and what the computer’s output was. You can also paste and execute commands directly into the console, instead of through the script file. This space will also be used exhaustively.
Upper-right: Four tabs:
evolved)Lower-right: Five tabs:
If you want to use RStudio, there are a series of configurations that we highly recommend you have. You can access them by going to the upper part of the screen (the one that contains the tabs “File”, “Edit”, “Code”, “View”, etc), clicking Tools > Global Options, and then editing options. Opinions on the best configuration vary, but below you have the link to a blog post that shows a possible configuration that might be helpful during our classes: (link: https://www.r-bloggers.com/2019/05/my-rstudio-configuration/)
Use your time to get used to all this new software.
In this short tutorial we will help you to navigate through your files. You can think of this as a checklist to use at the start of any of the labs in this class. Steps 1-4 have to be done before any lab. Steps 5 and 6 will be needed depending on the lab.
We start by revising what the “Desktop” of your computer is – the standard folder most computer operating systems (i.e., Windows, MacOS, Linux…) have. It is the first “place” your computer puts you in when you turn it on, seen in the screen shot below, which is my Desktop: