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"))
Examples
# 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"
#> [1] "/home/user/data"
print(output_path) # "/home/user/output"
#> [1] "/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"
#> [1] "/tmp/analysis"