# Basic Path Configuration

# Understanding Path Configuration

This guide walks through how to set up basic path configurations in your `_envsetup.yml` file.

## Configuration Structure Levels

### Level 1: Execution Environment

Scripts typically execute in different environments depending on your workflow:

    default:

    dev:

    qa:

    prod:

### Level 2: Paths and Autos

Each execution environment can have different configurations:

    default:
      paths:
      autos:

    dev:
      paths:
      autos:

    qa:
      paths:
      autos:

    prod:
      paths:
      autos:

### Level 3: Specific Configuration

Configure the actual environment settings:

    default:
      paths:
        data: "/demo/DEV/username/project1/data"
        output: "/demo/DEV/username/project1/output"
        programs: "/demo/DEV/username/project1/programs"

## Working Example

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)

## Loading and Using the Configuration

    # Load the configuration
    envsetup_config <- config::get(file = config_path)

    # Apply the configuration to your R session
    rprofile(envsetup_config)
    #> Assigned paths to R_GlobalEnv

## Accessing Your Configured Paths

Once configured, your paths are available in the `envsetup_environment` environment within the envsetup package environment:

    # See all available path objects
    ls(envsetup_environment)
    #> [1] "object_metadata"

    # Access individual paths
    get_path(data)
    #> [1] "/demo/DEV/username/project1/data"
    get_path(output)
    #> [1] "/demo/DEV/username/project1/output"
    get_path(programs)
    #> [1] "/demo/DEV/username/project1/programs"

## How It Works

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()`

## Benefits

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

## Next Steps

Now that you understand basic path configuration, the next guide will show you how to manage multiple environments (dev, qa, prod) with different configurations.