Chapter 4 R Projects

Hello!

This tutorial will provide a basic overview of R projects and markdowns!

4.1 Working Directory

The Working Directory is the folder that your computer is “focused on.” When you import data from your computer into R, you must make sure that the dataset and the R file are in the same folder.

You can use the function getwd() to figure out the working directory you are in. You can set the working directory using the setwd() function, or by going to Session –> Set Working Directory.

getwd()
## [1] "C:/Users/comm-lukito/Documents/J381M/j381m_bookdown"
#setwd()

In the above chunk of code, setwd() does not run because it is “commented.”

4.2 Projects

While getwd() and setwd() are useful for navigating files within RStudio, your projects will most likely be stored in one folder (as in: you wat your code and data in the same general place on your computer so you’re not hopping back between multiple folders). Thus: Projects. When you create a project, you associate it with a working directory, making it easier to return back to that project.

For folder maintenance (and my sanity), I try to stick to “one research project, one R project”, though my more complex projects (with multiple papers) may be more like “one research paper, one R project.” In this class, I recommend doing one of the following: * One week, one new project (this means you will have about 14) * One dataset, one project (this class will use 3 core datasets)

To create a new project, click the “File” dropdown menu in the upper left corner, and then “New Project”. This will cause a pop up window to appear; the pop up should look like the screenshot below.

Creating a new directory
Creating a new directory