RStudio is a popular integrated development environment (IDE) with several point-and-click features that make using the R programming language and software environment easier. It works on multiple Operating Systems (OS) including Windows, macOS, Linux, and the online RStudio Cloud version.
How R interacts with directories and the OS is very important. The current working directory or location where R thinks work happens, and the location for all files, can be structured and managed in a variety of ways. When working with RStudio, the RStudio Project feature provides an option that uses a single folder as the current working directory and the default location for all files including input data files, RScripts, notes, as well as output files. This makes it easy to organize and share projects with others, and when dealing with multiple analysis workflows, projects can be created for each analysis workflow to keep them separate.
Creating a New RStudio Project
To create a new project, open RStudio, navigate to the top right and click the RStudio Project menu to choose New Project.
Then choose a location on the OS for the new project, either New Directory or Existing Directory. If New Directory is chosen, assign it a Directory name and click Create Project to complete the process.
A new RStudio Project gets created and saved outside of RStudio onto the OS as a single project folder. An R project file (with an .Rproj file extension) also gets created and saved within the new project folder on the OS. For example, if the new RStudio Project folder is named DirectoryName, an R project file DirectoryName.Rproj gets created automatically. Input files (data, notes, other files related to the project) can be added to the new folder (DirectoryName). Also, all output files generated during the RStudio session will be added to the new folder.
The RStudio Project can be conveniently reopened by double-clicking on the R Project file (DirectoryName.Rproj) within the folder on the OS outside of R or by using the RStudio File menu and choosing Open Project.
When the project is opened, the current working directory will automatically be set to the folder on the OS and running getwd() will confirm that location. Visit RStudio Support to learn more.
References:
- rstudio.com/products/rstudio/download
- r-project.org
- support.rstudio.com/hc/en-us/articles/200526207-Using-Projects