Body
Question
How do I make my Rstudio project platform independent and utilize relative paths for portability?
Answer
1. Create a new project with renv.
Example project: my_research_project
2. Install and load here package.
3. Build and use platform independent paths.
Example project directory structure:
my_research_project/
│── my_research_project.Rproj
│── data/
│ └── raw_data.csv
└── scripts/
└── analysis.R
Example R code snippet:
library(here) # to setup path
library(readr) # to read csv file
# Build the path dynamically
data_path <- here("data", "raw_data.csv")
# Read the data
my_data <- read_csv(data_path)
4. data_path is now relative to my_research_project and platform independent. my_data will be populated with contents of raw_data.csv regardless of operating system.