Learn R Programming

envsetup (version 0.3.0)

get_path: Get Path Object from Environment

Description

Retrieves a path object from the specified environment using non-standard evaluation. The function uses substitute() to capture the unevaluated expression and get() to retrieve the corresponding object.

Usage

get_path(path, envir = getOption("envsetup.path.environment"))

Value

The path object stored in the specified environment under the given name.

Arguments

path

An unquoted name of the path object to retrieve from the environment.

envir

The environment to search for the path object. Defaults to the value of getOption("envsetup.path.environment").

See Also

Examples

Run this code
# Create a custom environment and store some paths
path_env <- new.env()
assign("data_dir", "/home/user/data", envir = path_env)
assign("output_dir", "/home/user/output", envir = path_env)

# Set up the option to use our custom environment
options(envsetup.path.environment = path_env)

# Retrieve paths using the function
data_path <- get_path(data_dir)
output_path <- get_path(output_dir)

print(data_path)    # "/home/user/data"
print(output_path)  # "/home/user/output"

# Using with a different environment
temp_env <- new.env()
assign("temp_dir", "/tmp/analysis", envir = temp_env)
temp_path <- get_path(temp_dir, envir = temp_env)
print(temp_path)    # "/tmp/analysis"

Run the code above in your browser using DataLab