inst/templates/use_here_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_here_directory()
}

# Set directory, then load modules without
# relative path
# i.e. box::use(. / a / module)
# vs. box::use(a / module)
use_here_directory <- function() {
    box::use(cli[cli_h1, cli_alert_info, cli_alert_success, cli_alert_danger])
    box::use(here[here])

    options(box.path = here())

    if(!is.null(getOption('box.path'))) {
        cli_alert_success(
            glue("Box directory set to here() directory: {getOption('box.path')}")
        )
        cli_alert_info("Load local modules with the relative path './'")
    } else {
        cli_alert_danger("Failure to set box.path")
    }

}
ElianHugh/boxingtape documentation built on Feb. 13, 2021, 12:48 a.m.