This cheatsheet covers how to control and troubleshoot the working directory in R, RStudio Desktop, and RStudio Cloud. A correct working directory makes data import, script sourcing, and project management much smoother.
Instead of just:
rstudio .
Use:
rstudio --cwd /path/to/your/directory
Example:
rstudio --cwd /c/workspace/My_Projects/alarm-projects
This ensures RStudio starts in the specified directory.
- Menu:
Session
→Set Working Directory
→Choose Directory...
- Shortcut: Ctrl + Shift + H
- R Console Command:
setwd("C:/workspace/My_Projects/alarm-projects")
- Go to
Tools
→Global Options
→General
- Under Default working directory, set your path (e.g.,
C:/workspace/My_Projects/alarm-projects
) - Click Apply and restart RStudio
RStudio Projects automatically set the working directory to the project folder.
File
→New Project
→Existing Directory
- Select your folder (e.g.,
C:/workspace/My_Projects/alarm-projects
) - RStudio creates a
.Rproj
file—always open this file to launch the project with the right directory!
- RStudio Cloud always starts in the project’s root directory.
- For reproducibility, always use RStudio Projects in the cloud too.
- To check your current directory:
getwd()
- To change it:
setwd("/cloud/project/subfolder")
- Upload files to
/cloud/project
for easy access.
- Check current directory:
getwd()
- Set working directory:
setwd("/path/to/your/directory")
- Paths on Windows: use either
/
or double backslashes\\
(never single\
). - Always check your current directory with
getwd()
if file loading fails. - Use Projects whenever possible—they save a ton of headaches!
Pro Tip:
Always use RStudio Projects for each analysis or codebase. They save window layouts, history, and—most importantly—set your working directory automatically!
Last updated: 2025-06-26
R Packages for Data Analytics & Engineering
This list of R packages is an excellent starting point for a professional data analyst. It covers a wide range of essential tasks, from data manipulation and visualization to reporting and project management. Here's a detailed breakdown of the list and some additional recommendations.
High-Quality Package Selection
The packages listed are widely recognized and frequently used in the data analysis community. Here's a look at their primary functions:
Core Data Science Workflow:
ggplot2
,dplyr
,readr
,stringr
,forcats
, andtibble
.summary()
function.Data Manipulation and Visualization:
tidyverse
, it provides a consistent set of verbs to solve the most common data manipulation challenges.tidyverse
, it provides a fast and friendly way to read rectangular data like CSV files.tidyverse
package offers a cohesive set of functions for working with strings, which is crucial for handling text data.tidyverse
package that provides tools for working with categorical variables (factors).tidyverse
. They offer a more user-friendly printing method and are stricter in their behavior, which helps to catch errors earlier.Reporting and Project Management:
renv
is now the recommended successor.Specialized Analysis:
Additional Essential R Packages to Consider
The above list is very thorough, but here are a few more packages that are highly recommended for a professional data analyst:
tidyverse
. It provides functions to help you create "tidy" data, where each variable is a column, each observation is a row, and each type of observational unit is a table. It's indispensable for data cleaning and reshaping.dplyr
for data manipulation. It is renowned for its high performance and memory efficiency, making it a great choice for working with very large datasets.shiny
is the go-to package.renv
is the modern successor topackrat
for project dependency management. It is now the recommended tool for creating reproducible R environments.Packages for Machine Learning
If your role as a data analyst extends to predictive modeling and machine learning, you should also consider:
tidyverse
. It provides a consistent and flexible framework for the entire modeling process.Presentation Tools
Use modern, professional business slides in R, Quarto + reveal.js which is arguably the best overall.