Skip to contents

This function will remove any autos that have been set from the search path

Usage

detach_autos()

Value

Called for its side-effects.

Examples

tmpdir <- tempdir()
print(tmpdir)
#> [1] "/tmp/RtmpQ1GZBD"

# 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/RtmpQ1GZBD/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")))
#> Assigned paths to R_GlobalEnv
#> Sourcing file:  '/tmp/RtmpQ1GZBD/demo/DEV/username/project1/functions/dev_function.r' 
#> 
#>  The following objects are added to .GlobalEnv:
#> 
#>     'dev_function'
#> 
#> Sourcing file:  '/tmp/RtmpQ1GZBD/demo/PROD/project1/functions/prod_function.r' 
#> 
#>  The following objects are added to .GlobalEnv:
#> 
#>     'prod_function'
#> 

# show dev_function() and prod_function() are available and print their location
dev_function()
#> <environment: 0x56007eb76630>
prod_function()
#> <environment: 0x56007ebd9140>

# remove autos from search
detach_autos()