This guide walks through how to set up basic path configurations in
your _envsetup.yml
file.
Scripts typically execute in different environments depending on your workflow:
Each execution environment can have different configurations:
Let’s create a practical example for a project called project1 that needs data input, result output, and program storage locations.
library(envsetup)
# Create temporary directory for demonstration
dir <- fs::file_temp()
dir.create(dir)
config_path <- file.path(dir, "_envsetup.yml")
# Write a basic config file
file_conn <- file(config_path)
writeLines(
"default:
paths:
data: '/demo/DEV/username/project1/data'
output: '/demo/DEV/username/project1/output'
programs: '/demo/DEV/username/project1/programs'", file_conn)
close(file_conn)
Once configured, your paths are available in the
envsetup_environment
environment within the envsetup
package environment:
The rprofile()
function:
1. Creates a special environment called
envsetup_environment
2. Populates it with your configured path objects
3. Makes these objects accessible in your code via the
get_path()
, read_path()
, and
write_path()
With this setup:
Consistency: All team members use the same path structure
Flexibility: Easy to change paths without modifying code
Clarity: Path purposes are clearly defined
Maintainability: Centralized configuration management
Now that you understand basic path configuration, the next guide will show you how to manage multiple environments (dev, qa, prod) with different configurations.