Using RStudio in Stat 220

There will be a lot of RStudio content thrown your way this term, most in the form of .Rmd (R Markdown) files. To stay organized, I strongly suggest you create a stat220 folder that contains the following subfolders:

To get started with this organization, follow the steps below.

File organization: Using maize

The server (online) version of RStudio is run from a Unix server. You can navigate this file system using Unix commands, but I assume that most or all of you will just use RStudio to access your files on this server.

1. In RStudio, click the Files tab in the lower right-hand window. Note: this is not the same as the File menu option.

2. Verify that you are in your HOME folder (should simply say Home right under the New Folder button). To navigate to your Home folder (if somehow you are not in it), click the button (far right side of the Files tab) and enter a ~ (tilde) symbol

3. Click the New Folder button and name the folder stat220.

4. Click on this newly created (empty) stat220 folder. Within the folder create another New Folder and name it assignments.

5. Within the stat220 folder, create an RStudio project called activities with the following steps:

  • a. Click the Project button in the upper right corner of your RStudio window and select New Project….

  • b. Select New Directory and then New Project

  • c. Enter activities as the Directory name and use the Browse button to find your stat220 folder. Then click Create Project.

  • d. You should now have a new folder called activities in your stat220 folder and this folder will contain an RStudio project .Rproj. Feel free to add subfolders to this activities folder (e.g. slides, examples, etc).

Warning: Do not create an RStudio project in the main stat220 folder because it is not good practice to have RStudio projects in subfolders of another project (e.g. a project within a project is not recommended).

File organization: Using your own RStudio

Create a folder called stat220 somewhere on your computer. Within this folder create an assignments subfolder. Then complete step 5 from above to create a activities RStudio project folder.

RStudio projects

Once you’ve created a project, your R session should be running within that project folder. You can check which project you are in by checking the project name in the upper right part of your RStudio window. Here we see the activities project is open:

Running R from an RStudio project sets your working directory to the project folder:

This allows for easy file path access to all files related to this project.

To start a project, click on the .Rproj file or use the Open Project… option shown in step 5 above.

Best practices (or what not to do)

  • Never save files to a lab computer hard drive (e.g. desktop, downloads, etc). They will be erased when you log off.
  • Do not use gmail as a file storage system! Avoid emailing yourself files that you created (and saved) on a lab computer. Eventually you will lose work this way.
  • Avoid using online versions of google drive and dropbox. Similar to gmail, downloading, editing a doc, then uploading it back to drive/dropbox is another great way to lose work.
  • Avoid this and this.

Acknowledgments

This guide is based on the guide from Katie St. Clair and is licensed under the CC BY-NC 3.0 Creative Commons License.