1.1 How to use this Book

1. Book Structure

This book has weekly chapters that correspond to course modules, with three parts:

a) Getting Started

  • Review of R Skills: check whether you need to build or brush up your R skills before starting the course:
    • Basic R Programming: introduction to R objects and functions. Prerequisite.
    • R Graphics: learn to create figures with base R and with ggplot2. Optional.

b) Basic Topics

  • These 8 weekly modules are streamlined to build the necessary R skills and brush up statistics knowledge. Best complete these in sequence.
  • Each module has the following components:
    • Video: introduces the R and stats topics
    • Interactive Tutorial: swirl course to practice R programming
    • Worked Example: worked example by the weekly experts from the ‘DGS Landscape Genetics’ course.
    • Bonus Materials: some weeks include bonus vignettes with optional advanced topics.

c) Advanced Topics

  • These weekly modules build on the skills developed in Basic Topics. You may pick and choose from the Advanced Topics according to your interests.
  • Each weekly modules contains:
    • Worked Example: worked example by the weekly experts from the ‘DGS Landscape Genetics’ course.
    • Bonus Materials: some weeks include bonus vignettes with optional advanced topics.

2. Find what is relevant for you

a) How to use the labs

Weeks 1 - 8:

  • Beginners:
    • watch video
    • do tutorial to build basic R programming skills
    • read worked example, focus on content
  • Intermediate:
    • watch video
    • check weekly tutorial functions: do tutorial to brush up?
    • understand worked example, focus on content and code
    • do R exercise to practice coding
  • Advanced:
    • check video slides: watch video to brush up on concepts?
    • R exercise?
    • adapt worked example to own data

By Week 9: you will be at least at ‘intermediate’ level if not a pro!

b) Check contents

  • Videos: Check first weekly slide, browse slides for each week
  • Interactive tutorials: check weekly list of commands for each chapter
  • Worked examples: check List of R Packages by Vignette; check introduction section for each worked example (or bonus vignette)

3. Course R package ‘LandGenCourse’

a) Practice good R hygiene

Please update or install the following before installing ‘LandGenCourse’:

Windows:

Mac: please follow the order below exactly!

b) How to install (or update) ‘LandGenCourse’

if (!require("remotes")) install.packages("remotes")
remotes::install_github("hhwagner1/LandGenCourse")
library(LandGenCourse)

Hints:

  • Make sure you load the package (library(LandGenCourse)) after installing it!
  • Check whether the add-ins 0 - 4 are available: in the RStudio menu, click on the drop-down menu Addins.
  • If the add-ins 0 - 4 don’t appear, rerun the code above (install and load package LandGenCourse). Sometimes this seems to be necessary.

c) How to install dependencies

The previous step only installed the absolutely required dependencies (i.e., R packages that LandGenCourse needs so that it can be installed). However, the weekly chapters will require additional R packages. There are two ways to install them:

Recommended: Bulk install

  • Use the Addin 0. Install Packages to bulk install most or all packages needed to run the worked examples.
  • Simply click on the add-in 0. Install Packages (alternatively, you could run this code: installDGS())
  • If asked whether to install some package from source (Do you want to install from sources the package which needs compilation? (Yes/no/cancel)), you may enter: no (this is faster)
  • If the installation stops with an error API rate limit exceeded, the best thing to do is to wait 30 min and run the Addin 0. Install Packages again. Don’t worry, this won’t start the installation process again, it will resume where it broke off.
  • If you often install packages from Github, you may want to follow up on the advice printed with the error message:
    • Use usethis::create_github_token() to create a Personal Access Token.
    • Use usethis::edit_r_environ() and add the token as GITHUB_PAT.
  • If you do so, the second line above will open the file .Renviron in RStudio. Enter GITHUB_PAT="myPAT" on the last line (replace myPAT by the PAT you generated using the first line). Make sure to include an empty line after it! Save the file and restart R.

Alternative: Install as you go

  • This option is not suitable if you are planning to do the interactive swirl tutorials! Use bulk installation instead (see above).
  • Newer versions of RStudio will warn you when a R notebook (.Rmd) that you opened requires R packages that are not installed.
  • The warning contains a link Install, click on it to install the missing packages.

d) How to use the R package LandGenCourse

The package installs four more Addins in RStudio. Each will provide you with some dropdown menu choices.

  • 1. Watch Course Video: opens a video resource from course “Landscape Genetic Data Analysis with R”.
  • 2. Start Tutorial: installs swirl course “Landscape_Genetics_R_Course” and prints instructions.
  • 3. Choose Worked Example: opens vignette file (.html, .Rmd, or .R) with a worked example from course “Landscape Genetic Data Analysis with R”.
  • 4. Open Cheat Sheet: opens selected R cheat sheet.

e) Video instructions for beginners

This video walks through the process of installing devtools, the course package, and using the RStudio Add-Ins. Intro_LandGenCourse_small.mp4