Summary and Schedule
IRIM R Workshops
Presented by Kathryn Napier, with material adapted from from several
Carpentries
resources, including:
The English version of the IRIM R Workshop website is located here.
A Mongolian version of the IRIM R Workshop website is located here.
The Mongolian text is automatically translated from the original English text using Google Translate.
The Carpentries aim is to teach researchers basic concepts, skills, and tools for working with data so that they can get more done in less time, and with less pain. This is an introduction to R designed for participants with no programming experience. The workshop includes:
The workshop starts with information about the R programming language and the RStudio interface.
Introduction to
RandR StudioIntroduction to
R Packages,R MarkdownandR NotebooksStarting with data in
RManipulating Data with
dplyrandtidyr
This lesson assumes no prior knowledge of R or
RStudio and no programming experience.
| Setup Instructions | Download files required for the lesson | |
| Duration: 00h 00m |
1. Introduction to R
and RStudio
|
Why should you use R and RStudio?How do you get started working in R and
RStudio?::: |
| Duration: 00h 45m |
2. Introduction to
R Packages, Markdown and
Notebooks
|
What is an R package?How to install R
packages?What is R Markdown and
R Notebooks?How can I integrate my R code
with text and plots?How can I convert .Rmd files to
.html?::: |
| Duration: 01h 45m | 3. Starting with Data |
How does R store data?What is a data.frame? How can I read a complete .csv file into
R?How can I get basic summary information about my dataset? How can I change the way R treats strings in
my dataset?Why would I want strings to be treated differently? How are dates represented in R and how can
I change the format?::: |
| Duration: 02h 57m |
4. Manipulating Data with
dplyr and tidyr
|
How can I select specific rows and/or columns from a dataframe? How can I combine multiple commands into a single command? How can I create new columns or remove existing columns from a dataframe? How can I reformat a data frame to meet my needs? ::: |
| Duration: 04h 27m | 5. Quantitative Data Analysis in R |
What statistical tests should I use? How can I run multiple tests at once? ::: |
| Duration: 05h 57m | Finish |
The actual schedule may vary slightly depending on the topics and exercises chosen by the instructor.
Preparations
This series of workshops are designed to be hands-on, so learners
must have R and RStudio installed on their
computers. You also need to be able to install a number of R packages,
create directories, and download files.
Install R and RStudio
R and RStudio are two separate pieces of
software:
-
Ris a programming language and software used to run code written inR. -
RStudiois an integrated development environment (IDE) that makes usingReasier. In these workshops, we useRStudioto interact withR.
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.
- Download
Rfrom theCRAN website. - Run the
.exefile that was just downloaded - Go to the
RStudio download page - Click
INSTALL RSTUDIO DESKTOP FOR WINDOWS - Run the
.exefile that was just downloaded - Once it’s installed, open
RStudioto make sure it works and you don’t get any error messages.
- Download
Rfrom theCRAN website. - Select the
.pkgfile for the latestRversion - Double click on the downloaded file to install
R - It is also a good idea to install
XQuartz(needed by some packages) - Go to the
RStudio download page - Under
InstallersselectMac OS 13+ - RSTUDIO-xxxx.yy.z-zzz.dmg(where x = year, y = month, and z represent version numbers) - Double click the file to install
RStudio - Once it’s installed, open
RStudioto make sure it works and you don’t get any error messages.
- Click on your distribution in the
Linux folder of the CRAN website. Linux Mint users should follow instructions for Ubuntu. - Go through the instructions for your distribution to install
R. - Go to the
RStudio download page - Select the relevant installer for your Linux system (Ubuntu/Debian or Fedora)
- Double click the file to install
RStudio - Once it’s installed, open
RStudioto make sure it works and you don’t get any error messages.
Update R and RStudio
If you already have R and RStudio
installed, first check if your R version is up to date:
- When you open
RStudioyourRversion will be printed in the console on the bottom left. Alternatively, you can typesessionInfo()into the console. If yourRversion is 4.0.0 or later, you don’t need to update R for this workshop. If your version of R is older than that, download and install the latest version ofRfrom theRproject websitefor Windows,for MacOS, orfor Linux - It is not necessary to remove old versions of R from your system, but if you wish to do so you can check How do I uninstall R?
- After installing a new version of
R, you will have to reinstall all your packages with the new version. ForWindows, there is a package calledinstallrthat can help you with upgrading yourRversion and migrate your package library. A similar package calledpacmancan help with updatingRpackages across To updateRStudioto the latest version, openRStudioand click onHelp > Check for Updates. If a new version is available follow the instruction on screen. By default,RStudiowill also automatically notify you of new versions every once in a while.
The changes introduced by new R versions are usually
backwards-compatible. That is, your old code should still work after
updating your R version. However, if breaking changes
happen, it is useful to know that you can have multiple versions of
R installed in parallel and that you can switch between
them in RStudio by going to
Tools > Global Options > General > Basic.
While this may sound scary, it is far more common to
run into issues due to using out-of-date versions of R or
R packages. Keeping up with the latest versions of
R, RStudio, and any packages you regularly use
is a good practice.
Install required R packages
During the workshops we will need a number of R
packages. Packages contain useful R code written by other people. We
will use the tidyverse package.
To try 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
Enter (Windows and Linux) or
Return (MacOS) to execute the
command.
R
install.packages("tidyverse")
install.packages("help")
Alternatively, you can install the packages
usingRStudio'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
library(tidyverse)
library(here)
If you do not see an error like
there is no package called ‘...’ you are good to go!
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. We will
introduce the renv package at a future workshop.