How do I set the working directory in R?

How do I set the working directory in R?

Answered in Getting Started with R and RStudio: https://learnadv.com/courses/getting-started-with-r-and-rstudio/

To set the working directory, you'll need the file path. 

I’ve included a few resources the detail how to find the path for various devices.


Set the Working Directory
Once you have your path, you will set your working directory via the setwd() function

#Example for my PC
setwd("C:/users/dillon/desktop/example")
Note, that for the setwd() function you need to place the path in quotations and ensure you use forward slashes ( / )and not back slashes (\).

If the chunk above ran successfully, you should see the working directory at the top of your console in Rstudio.


    • Related Articles

    • What is a working directory in R?

      Answered in Getting Started with R and RStudio: https://learnadv.com/courses/getting-started-with-r-and-rstudio/ The working directory is a folder on your computer that R has access to. This folder is where R loads in data, export results, and in ...
    • What are the common files used in R?

      Answered in Getting Started in R and Rstudio course: https://learnadv.com/courses/getting-started-with-r-and-rstudio/ R scripts (.R files) In most uses of R, we create scripts. Scripts are a collection of code and functions written in the R language ...
    • Do I have to download Rstudio to code in R?

      Answered in Getting Started with R and Rstudio course at: https://learnadv.com/courses/getting-started-with-r-and-rstudio/lessons/section-0-introduction-to-r-2/topics/0-1-1-what-is-r-and-rstudio/ Technically speaking, you can run just the R ...
    • Where can I download R? Where can I download Rstudio?

      Excerpt from the Getting Started with R and Rstudio free-course found here: https://learnadv.com/courses/getting-started-with-r-and-rstudio/lessons/section-0-introduction-to-r-2/topics/0-1-1-what-is-r-and-rstudio/ Installing R To install R you will ...
    • Phi Statistic for Indicator Species

      The Phi statistic is often used to represent Indicator Species. For example, the popular R package indicspecies relies heavily on reporting the Phi statistic from Chytrý et. al 2002 Indicator Species are those which signal some feature of the ...