Starting RStudio: Friday Oct 27, 2017 Webinar
4:00 EDT, 3:00 CDT, 2:00 MDT, 1:00 PDT.
– Link to the recording of the webinar
RStudio provides the means to write course notes, handouts, and even interactive tutorials. Together with GitHub, it lets you easily set up course-specific web sites and create materials for those sites. Oh … and since it built on the R software, it’s fully integrated with modern systems for data management, statistics, modeling, and even machine learning.
This webinar is an introduction to RStudio with a focus on creating and updating course web sites and writing course handouts.
In StatPREP Webinar I, we introduced GitHub for creating course web pages where you can post data, instructions, and other resources that you want your students to be able to access.
In this webinar (StatPREP Webinar II), you’ll start to use RStudio. In particular you’ll connect RStudio to GitHub so that you can use RStudio to update and extend your web site.
In StatPREP Webinar III, you’ll start using R and Learnr.
- You need an account on the StatPREP RStudio service. You can get an account by submitting this form. We also have some guest accounts available for last-minute arrivals. Needless to say, the service is free.
- You need a GitHub account. This is also free. If you already have a GitHub account, use that. If you don’t, set one up now at GitHub.com. Two steps:
– Pick your username and password and press “Sign up.”
– Go to your email and validate your account. GitHub will send you a link for that purpose (but this might take a few minutes).
To participate in the webinar
You’ll be using two browser tabs simultaneously, so you may want to position them side by side.
- Bring up your web browser and open a new tab. Go to this link for the live webinar. The Zoom web conferencing software will ask you for some permissions. Give them.
- Open a second new tab and direct it to the login screen for the StatPREP RStudio service: StatPREP.org/rstudio.
If you have a user account for the StatPREP RStudio service, you can log in with those credentials. If not, we may be able to set you up with one very quickly. We also have several guest accounts available just in case you come along in the middle of things.
… and keep in mind for after the webinar …
The webinars are only one form of support that we offer to StatPREP participants.
- We’ll be scheduling live-help sessions about the webinar a couple of weeks after each one.
- Remember to stay in touch with your hub leader for help with using any of the techniques covered in the webinar.
- As we start to set up our national network linking hubs, you should feel comfortable using the “prototype” of that network for support: write to Danny Kaplan (firstname.lastname@example.org) with questions and we can arrange one-on-one support through a web conference as needed.
FEEDBACK We need your feedback about the webinar so that we can improve the format and content and so that our sponsors (MAA, ASA, AMATYC, NSF) can get a handle on the extent to which we are succeeding. Please fill out the survey at this link. (The survey will ask for the date of the webinar: Oct 27, 2017.) If you’re watching the video recording of the webinar, your feedback is equally important.
Once you have logged in to the StatPREP RStudio service, your browser tab will look like this:
- Next to the big blue R, there’s a menu bar for the app with familiar names like File, Edit, and so on. Remember that when working with RStudio you’ll be using this menu bar, not the one for your browser. At the very far right of the menu bar, your user ID is shown (guest115 in the picture). The menu bar also has a second row with icons, etc.
- At the far right of the menu bar, beneath your user ID, there’s a drop-down menu labelled “Project:”. This will be important later on. (In the picture, the menu is labelled “Project: (None)”.)
- Underneath the menu bar are three small “panes.” This word is used because you have the whole browser window, and the parts of a window are called … right, panes. Within each pane there are multiple “tabs.”
Remember the hierarchy: Windows contain Panes contain Tabs. This helps when talking to other people.
The three panes in the picture are
- The biggest pane, one the left, which contains a tab named “Console.” If you have used R before, you’re probably used to typing in the console. But that’s not what we’re going to do today.
- The pane on the top right, displaying a tab named “Environment.”
- The pane on the bottom right, displaying a tab “Files.” In a few minutes, you’ll also use the “Viewer” tab.
And, soon enough, you’ll be creating a new pane for editing documents.
Your first project
We’re going to create two projects today. The first is just for practice. The second will be connected to your course web page on GitHub.
- Remembering to use the menu bar with the big blue R, go to the File menu and select “New Project…” You’ll see the following menu.
- Select “New Directory” then the top choice, “New Project,” and then, in the box labelled “Directory name:”, type
ForPractice. (As a rule, keep project names simple with just letters, numbers, the underscore character, and without any spaces.) Then just press the “Create Project” button.
Your window will refresh and at the far right of the menu bar you’ll see “ForPractice” as the name of the dropdown menu.
Look also at the “Files” tab. The file path, shown in blue next to the house icon, will be “Home/ForPractice”. And, underneath that, you’ll see a file named “ForPractice.Rproj”. Leave that file alone. Every project you create will have a similar file with a
Creating a document
We’re going to write a handout for your course.
- Select File/New File/New R Markdown …
- Save the document as is with a reasonable name:
Lesson_A. (Remember, no spaces in the name!) The
.Rmdsuffix will be added automatically.
- Compile the document to HTML by pressing the “Knit” button.
– Your work process should be:
a. Make a small change, e.g. a paragraph.
b. Compile the document to make sure the change worked.
– As you gain experience, your changes won’t have to be so small.
4. Compile the document to PDF.
– In the downward-pointing triangle, select “Knit to PDF”.
5. Download the PDF document to your own machine so that you can print it out.
Second Project: Your course web site
Next, we’ll put the document on your course web site so that students can access it directly. We’ll do this in a different project, so consider your previous document as scratch work.
- Get a clone link to your GitHub course web site repository. (If you don’t have one, clone the Stat101 repository into your own GitHub account, reset the name, turn on gh-pages in the doc directory, and copy the clone link.)
– Use the green bar, making sure it’s set to HTTP.
– Copy the link.
2. Use the link to create a new project with “Version Control.”
3. Edit the front page of your
6. Set up your GitHub credentials.
– This is a one-time operation. You do it now and you won’t need to do it again on this server. But you will have to repeat it on any other server or desktop machine you use to connect to the repository.
– Open Tools/Shell in the RStudio toolbar
– A new tab will open in the editing pane.
– Give these two commands, customizing each to your name and email address.
git config --global user.email "email@example.com" git config --global user.name "Your Name"
- Push your repository to GitHub
Patch for those working with stat101 clones from the last webinar: create an empty
.nojekyll file in the top directory of your repository. (Not in the
docs/ directory. The one above that.)
Frequently asked questions
- Why should I use the StatPREP RStudio service? Can’t I use my own computer or a service provided by my institution?
Absolutely! But there are some features that need to be set up. This setup is taken care of with the StatPREP RStudio service.
- Can I continue using the StatPREP RStudio service after the webinar?
Yes. But as StatPREP expands and the needs of our participants become more demanding, we’ll need eventually to switch to a more powerful server. So make sure that you are working with “projects” connected to GitHub. That way, whatever happens, you’ll be able to continue with your work on the new server (or even on your laptop or another machine/server).
- Do I need to use GitHub?
Yes and no. Many people use RStudio without GitHub. We think this sacrifices many important capabilities such as backup, publishing, and collaborating with others. We strongly encourage you to use GitHub from the beginning.
- Do I need to have a project open to use RStudio?
Again, yes and no. It’s a better practice to do all your work within a project. You can have as many projects as you want.
- When compiling Rmd -> HTML, the pop-up window containing the rendered document is hidden behind other windows. Can I fix this?
The easiest way to handle this is to configure RStudio to display the rendered document in a tab within RStudio. Go to Tools/Global Options then select the R Markdown item in the left column. Then, set the “Show output preview” menu to “Viewer Pane.”