inst/templates/use_global_directory.r

box::use(glue[glue])

.on_load <- function(ns) {
    box::use(cli[cli_h1, cli_div])

    module_name <- box::name()
    cli_div(theme = list(span.emph = list(color = "orange")))
    cli_h1(
        'Loading module "{.emph {module_name}}"'
    )
    use_global_directory()
}

use_global_directory <- function() {
    box::use(cli[cli_h1, cli_alert_info, cli_alert_success])
    box::use(. / module_lib[get_global_dir])

    options(box.path = get_global_dir())

    if (!is.null(getOption("box.path"))) {
        cli_alert_success(
            glue("Box directory set to global directory: {getOption('box.path')}")
        )
        cli_alert_info("Load local modules with the relative path './'")
        cli_alert_info("Directory can be manually set with option('module.dir' = ...)")
    } else {
        cli_alert_danger("Failure to set box.path")
    }
}
ElianHugh/boxingtape documentation built on Feb. 13, 2021, 12:48 a.m.