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/directoryExample:
rstudio --cwd /c/workspace/My_Projects/alarm-projectsThis ensures RStudio starts in the specified directory.
Update: better to use Rproj since we uses relative dir instead of specific path.
- 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
.Rprojfile—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/projectfor 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
Example Usage of R Packages for Data Analytics & Engineering
Based on our specific use cases for the Divvy bike data engineering project, here's a curated list of R packages optimized for our needs: I've created a curated list of 16 essential R packages specifically tailored for our Divvy data engineering project. Here's why this selection is optimized for our needs:
Key Highlights:
Core Advantages:
What I Excluded and Why:
arrow- We're using Redshift, not direct Parquet manipulationdata.table- Tidyverse is sufficient for our analysis scaleshiny- We're using Tableau Public for final dashboardstestthat- dbt handles our data testing needsProject-Specific Inclusions:
DBI,RPostgres,dbplyr- Essential for connecting R to our Redshift data warehousescales- Perfect for formatting revenue calculations ($0.19/minute, percentages)plotly- Interactive exploration of station utilization patternslubridate- Critical for analyzing trip timestamps and duration calculationsInstallation Strategy:
The artifact provides a phased installation approach so we can install packages as needed, plus the complete renv workflow for reproducible environments.
Essential R Packages for Divvy Data Engineering Project
Core Installation Command for renv
Package Categories and Justifications
1. Core Data Science Workflow (Essential)
tidyverse- Comprehensive suite including ggplot2, dplyr, readr, stringr, forcats, tibbletidyr- Data reshaping and cleaning (not automatically included in tidyverse)lubridate- Date/time manipulation (crucial for bike trip timestamps)janitor- Data cleaning and column name standardizationskimr- Quick dataset overviews and summary statistics2. Database Connectivity (Project-Specific)
DBI- Database interface foundationRPostgres- PostgreSQL/Redshift connectivitydbplyr- dplyr syntax for database queries (essential for Redshift integration)3. Visualization and Rapid Prototyping (Core Need)
plotly- Interactive visualizations for explorationscales- Scale functions for ggplot2 (revenue formatting, percentages)viridis- Color scales that are colorblind-friendlypatchwork- Combining multiple ggplot2 plots4. Presentation Tools (Your Preference)
quarto- Modern publishing system with reveal.js integrationknitr- Code chunk processing (required by quarto)rmarkdown- Markdown processing (quarto dependency)5. Project Management (Professional Standards)
here- Robust file path managementrenv- Package dependency management (already chosen)Packages NOT Recommended for Your Use Case
Skip These (Not Needed):
arrow- You're using Redshift, not Parquet files directly in Rdata.table- tidyverse approach is sufficient for your analysis scaletestthat- dbt handles data testing; R code will be exploratorySimDesign- Monte Carlo simulations not relevant to bike share analysisshiny- Using Tableau Public for final dashboardstidymodels/caret/mlr3- No machine learning requirements mentionedpackrat- Superseded by renvInstallation Strategy
Phase 1: Core Setup
Phase 2: Database Integration
Phase 3: Visualization Enhancement
Phase 4: Presentation Tools
Project-Specific Considerations
For Divvy Data Analysis:
lubridate- Essential for trip start/end time analysisscales- Format revenue calculations (dollar signs, percentages)dbplyr- Write dplyr code that translates to SQL for Redshiftplotly- Interactive exploration of station utilization patternsFor Business Presentations:
quarto+reveal.js- Professional slide presentationsviridis- Accessible color palettes for executive presentationspatchwork- Combine multiple revenue/usage chartsrenv Workflow
Total Package Count: 16 Essential Packages
This curated list focuses on your specific needs while avoiding bloat. The selection prioritizes:
This streamlined approach ensures fast installation, minimal dependency conflicts, and focused functionality for your Divvy bike data engineering project.