# 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