Marine-Semester_Intro-to-R

To minimize troubleshooting during the workshop, learners should follow the instruction below to download and install everything beforehand. If they are using their own computers this should be no problem, but if you are using a computer that is managed by the IT department, we might need help from an IT administrator.

Install R and RStudio

R and RStudio are two separate but related pieces of software:

If you don’t already have R and RStudio installed, follow the instructions for your operating system below. You have to install R before you install RStudio.

Windows

MacOS
Linux

Update R and RStudio

If you already have R and RStudio installed, first check if your R version is up to date:

To update RStudio to the latest version, open RStudio and click on Help > Check for Updates. If a new version is available follow the instruction on screen. By default, RStudio will also automatically notify you of new versions every once in a while.

Install required R packages

During Marine Semester courses you will likely need to use an R package or two. Packages contain useful R code written by other people. In the Quantitative Fisheries Analysis course, for example, students will use the packages dplyr, rEDM, ggplot2 and possibly others.

Like most tasks on the computer, there’s more than one way to go about this. Your Rstudio, for example, should have a Packages tab in the low right hand quadrant. It’s good to know how to do things from the Console, however.

To install these packages, open RStudio and copy and paste the following command into the Console window (look for a blinking cursor on the bottom left), then press the Enter (Windows and Linux) or Return (MacOS) to execute the command.

```{r eval=FALSE} install.packages(“ggplot2”)


Alternatively, you can install the packages using RStudio's graphical user 
interface by going to `Tools > Install Packages` and typing the names of the 
packages separated by a comma.

R tries to download and install the packages on your machine.
When the installation has finished, you can try to load the
packages by pasting the following code into the console:

```{r eval=FALSE}
library(ggplot2)

If you do not see an error like there is no package called ‘...’ you are good to go, and we’ll see you at the workshop!

Updating R packages

Generally, it is recommended to keep your R version and all packages up to date, because new versions bring improvements and important bugfixes. To update the packages that you have installed, click Update in the Packages tab in the bottom right panel of RStudio, or go to Tools > Check for Package Updates....

Sometimes, package updates introduce changes that break your old code, which can be very frustrating. To avoid this problem, you can use a package called renv. It locks the package versions you have used for a given project and makes it straightforward to reinstall those exact package version in a new environment, for example after updating your R version or on another computer. However, the details are outside of the scope of this lesson.

Contributors

** This material was adapted from **

François Michonneau, Tracy Teal, Auriel Fournier, Brian Seok, Adam Obeng, Aleksandra Natalia Pawlik, … Ye Li. (2019, July 1). datacarpentry/R-ecology-lesson: Data Carpentry: Data Analysis and Visualization in R for Ecologists, June 2019 (Version v2019.06.1). Zenodo. http://doi.org/10.5281/zenodo.3264888

The list of contributors to the original Data Carpentry lesson is available here.