This semester I am trying something a little new- the labs are now built as interactive documents using R-shiny. This is intended to give you instant feedback, because with no TA it can take me a while to give you feedback on your labs! Hopefully this helps your learning experience- please let me know what you think!

## Interactive labs

The interactive labs are available via an R package called “NRES746labs”. To access the interactive labs, use the following steps:

### Step 1.1: install devtools (first time only)

To do this, use the “Install” button on the “Packages” tab in Rstudio, or use the following command:

install.packages("devtools")

NOTE: you only have to do this once! That is, once you’ve installed a package on your machine it will always be there!

### Step 2: install the “NRES746labs” package from GitHub

Ultimately I may load this package to the CRAN repository, but for now it lives on GitHub (since I’ll be updating it a lot!). You can use the following code to install the package from GitHub:

devtools::install_github("kevintshoemaker/NRES746labs")

NOTE: this can take a while the first time, and lots of messages will pop up. If you’re asked to choose packages to update, I don’t think it matters what option you choose.

NOTE: you should re-install the package for every lab, since I’ll be updating frequently. For example, the package currently only includes lab 1 (I haven’t finished the interactive versions of lab 2-4 yet).

### Step 3: run the lab!

Now you have everything you need to run the lab. Use the following code:

library(NRES746labs)
learnr::run_tutorial("lab1","NRES746labs")

NOTE: the system doesn’t seem to work for Microsoft Edge, so make sure your default browser is Chrome or Safari.

NOTE: the shiny app will “use up” your R session, so if you want to work on your own script at the same time as you’re running the app, you’ll have to open up a second R session.

Hope this works! Good luck!

### DEBUGGING

Here are some tips if things don’t work right away:

2. If R throws errors like “can not remove package […]” then close all R sessions and go into your local package directory and delete the package manually. Then go back to R and reinstall the package. To find your local package directory, enter the following in your R session:

  Sys.getenv('R_LIBS_USER')

This seems to be easier said than done on a Mac!

1. If you try to run the tutorial through the base R GUI and not RStudio you may have to do the following:
• Go into Rstudio and find your ‘pandoc’ directory:
   Sys.getenv('RSTUDIO_PANDOC')
• Go back to your base R session and enter the following:
   Sys.setenv(RSTUDIO_PANDOC=[...your directory here...])
2. If you get an error stating that GitHub’s API rate limit has been exceeded (GitHub has a rate limit of 60 requests per hour for unauthenticated requests), the easiest solution is to create a GitHub access token (PAT). You can get a PAT by entering ‘usethis::browse_github_pat()’ in your R console and following the instructions. Then, add your PAT to your .Renviron file by entering ‘usethis::edit_r_environ()’ in your R console. Finally, in the ‘.Renviron’ file (the one that just opened up in Rstudio), type the following:
GITHUB_PAT=[your PAT here]
1. If nothing seems to work, try using one of the lab computers!