RStudio Cloud
Introduction
Using R/RStudio on your own laptop is the best approach for doing statistics. Alas, sometimes that is not possible, either because your laptop is broken or because you use something like an Ipad instead. (You can’t run R/Rstudio on an Ipad or other tablet. You can run them on a Chromebook, although doing so is tricky.)
Solution: RStudio Cloud managed by Simmons.
The basic idea is that RStudio (the company) runs an instance of R/RStudio (the programs) in the cloud on Linux machines. We can access and interact with those instances via the browser.
Setting Up RStudio Cloud
After your login with your Simmons details, you will see:
This is a working RStudio session. But it is not really the home page for RStudio Cloud. You can get to that homepage with File -> Quit Session …
. The real homepage looks like this:
Don’t worry about the details of this homepage yet. Instead, go back to the RStudio instance. (You can click New Session
on this page to get there. Once there, type:
remotes::install_github("PPBDS/primer.tutorials")
You might be asked to update some packages. If so, you should agree, probably by entering 1
and then hitting return. Because we have pre-installed all the required packages, this works quickly:
The output continues for another half a page or so. It is still useful to read the Getting Started chapter in the Primer. There is only one more command to issue:
primer.tutorials::prep_rstudio_settings()
And you are all set! Click (top right) on the Tutorial tab in the Environment pane and complete the Getting Started tutorial. (It is sometimes useful to click the Home icon — the little house with the red roof just under the Environment tab — on the Tutorial tab.)
Working on Tutorials
You work on tutorials in the cloud in the same way that you might work on them on your own machine. You have two options. First, you can work on them within the Tutorial tab itself:
Second, you can press the “Show in new window” button next to the Home icon. This will pull out the tutorial to its own window.
I recommend the first approach. Work in the Tutorial tab, but expand the width of the two panes on the right of the RStudio screen so that you can see more of the tutorial.
You can expand the width by just dragging the dividing line to the left.
Grey Out
If you aren’t actively working on a tutorial, it will become greyed out.
If you click the Home icon and then click the Start Tutorial button, it will come out of grey. This does not actually stop and restart the tutorial. It just “wakes up” the tutorial.
Restarting the R Session
We occasionally restart the R session (or the RStudio instance) when we are in the middle of a tutorial. This (almost) always causes RStudio to generate the “Terminate Jobs” box. (This box is sometimes hidden behind your browser.)
You need to agree to terminate the job, which is your tutorial in this case.
After you terminate, R restarts, leaving the tutorial to “grayed out.”
There is nothing wrong with this. Just close the tutorial window. Unfortunately, a problem often arises when you try and restart the same tutorial again. Doing so (always?) produces an error:
You can make the “Loading tutorial . . .” spinning wheel stop by hitting the Home icon. Unfortunately — and this is the biggest problem with RStudio Cloud — the only fix for this problem is to remove and reinstall the primer.tutorials package.
Working on Projects
Students working on their own laptops will do all their work within R projects connected to Github repositories. We will do the same in RStudio Cloud. Don’t worry about Github for now. But do start work by clicking New Project -> New RStudio Project
. Once the new project is created, you can click in its “Untitled” name and change its name to something sensible (with no spaces) like class-2022-09-09
. More to come on this topic.
Advice
Disaster may strike! For example, it is possible for you to have 75% done with a tutorial, and for the Cloud to fail, deleting all your anwers. Don’t panic! Don’t redo the work you have already done! Just do the rest of the tutorial and submit the remaining answers. Email Preceptor to inform him. You will get full credit!
When starting a new tutorial, always begin by removing and re-installing primer.tutorials.
remove.packages("primer.tutorials")
remotes::install_github("PPBDS/primer.tutorials")
It will sometimes be necessary to restart your R session in order to “see” the tutorials from the primer.tutorials package. One of my slogans is: You can never restart R too often. Other times you might just need to run the command
library(primer.tutorials)
.Quit your session once you are done. If you leave it open in your browser, you will use up too many hours.
I don’t think that quitting a tutorial halfway through and then coming back to it works as well in RStudio Cloud as it does on your own laptop. (I am still testing.) So, try to complete each tutorial in one sitting, downloading your answers and submitting them to Moodle.
Sometimes, the Tutorial tab is just spinning aimlessly, not showing you any tutorials to select. Clicking the Home icon often fixes that.
Sometimes weird stuff happens. You get a strange error message. The first trick to try and fix it is to remove and re-install primer.tutorials. Deleting and then reinstalling a package is often the best way to solve strange error messages. Restarting your R session often helps as well.