This function will remove any autos that have been set from the search path
Examples
tmpdir <- tempdir()
print(tmpdir)
#> [1] "/tmp/RtmpKPwpGu"
# account for windows
if (Sys.info()['sysname'] == "Windows") {
tmpdir <- gsub("\\", "\\\\", tmpdir, fixed = TRUE)
}
# Create an example config file\
hierarchy <- paste0("default:
paths:
functions: !expr list(DEV = file.path('",tmpdir,"',
'demo',
'DEV',
'username',
'project1',
'functions'),
PROD = file.path('",tmpdir,"',
'demo',
'PROD',
'project1',
'functions'))
autos:
my_functions: !expr list(DEV = file.path('",tmpdir,"',
'demo',
'DEV',
'username',
'project1',
'functions'),
PROD = file.path('",tmpdir,"',
'demo',
'PROD',
'project1',
'functions'))")
# write config
writeLines(hierarchy, file.path(tmpdir, "hierarchy.yml"))
config <- config::get(file = file.path(tmpdir, "hierarchy.yml"))
build_from_config(config)
#> ✔ Directories built
#> /tmp/RtmpKPwpGu/demo/
#> ├── DEV
#> │ └── username
#> │ └── project1
#> │ ├── data
#> │ ├── functions
#> │ ├── output
#> │ └── programs
#> └── PROD
#> └── project1
#> ├── data
#> ├── functions
#> ├── output
#> └── programs
# write function to DEV
writeLines("dev_function <- function() {print(environment(dev_function))}",
file.path(tmpdir, 'demo', 'DEV', 'username', 'project1', 'functions', 'dev_function.r'))
# write function to PROD
writeLines("prod_function <- function() {print(environment(prod_function))}",
file.path(tmpdir, 'demo', 'PROD', 'project1', 'functions', 'prod_function.r'))
# setup the environment
Sys.setenv(ENVSETUP_ENVIRON = "DEV")
rprofile(config::get(file = file.path(tmpdir, "hierarchy.yml")))
#> Attaching paths to envsetup:paths
#> Attaching functions from /tmp/RtmpKPwpGu/demo/PROD/project1/functions to autos:my_functions.PROD
#> Attaching functions from /tmp/RtmpKPwpGu/demo/DEV/username/project1/functions to autos:my_functions.DEV
# show dev_function() and prod_function() are available and print their location
dev_function()
#> <environment: 0x56089247cd58>
#> attr(,"name")
#> [1] "autos:my_functions.DEV"
prod_function()
#> <environment: 0x5608924ba278>
#> attr(,"name")
#> [1] "autos:my_functions.PROD"
# remove autos from search
detach_autos()