Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

tar_load_globals

Load globals for debugging, testing, and prototyping


Description

Load user-defined packages, functions, global objects, and settings defined in the target script file (default: _targets.R). This function is for debugging, testing, and prototyping only. It is not recommended for use inside a serious pipeline or to report the results of a serious pipeline.

Usage

tar_load_globals(
  envir = parent.frame(),
  script = targets::tar_config_get("script")
)

Arguments

envir

Environment to source the target script (default: _targets.R). Defaults to the calling environment.

script

Character of length 1, path to the target script file that defines the pipeline (_targets.R by default). This path should be either an absolute path or a path relative to the project root where you will call tar_make() and other functions. When tar_make() and friends run the script from the current working directory. If the argument NULL, the setting is not modified. Use tar_config_unset() to delete a setting.

Details

This function first sources the target script file (default: _targets.R) to loads all user-defined functions, global objects, and settings into the current R process. Then, it loads all the packages defined in tar_option_get("packages") (default: (.packages())) using library() with lib.loc defined in tar_option_get("library") (default: NULL).

Value

NULL (invisibly).

See Also

Examples

if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) {
tar_dir({ # tar_dir() runs code from a temporary directory.
tar_script({
  tar_option_set(packages = "callr")
  analyze_data <- function(data) {
    summary(data)
  }
  list(
    tar_target(x, 1 + 1),
    tar_target(y, 1 + 1)
  )
}, ask = FALSE)
tar_load_globals()
print(analyze_data)
print("callr" %in% (.packages()))
})
}

targets

Dynamic Function-Oriented 'Make'-Like Declarative Workflows

v0.10.0
MIT + file LICENSE
Authors
William Michael Landau [aut, cre] (<https://orcid.org/0000-0003-1878-3253>), Matthew T. Warkentin [ctb], Samantha Oliver [rev] (<https://orcid.org/0000-0001-5668-1165>), Tristan Mahr [rev] (<https://orcid.org/0000-0002-8890-5116>), Eli Lilly and Company [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.