Skip to contents

This function is designed to be used as the process_func in a tarflowr_run() call for hierarchical workflows. It takes a configuration object from tarflowr_project() and executes the specified targets pipeline.

Usage

tarflowr_run_subproject(config)

Arguments

config

A work unit object created by tarflowr_project().

Value

The value of the result_target from the sub-project.

Details

This function operates as a "black box" orchestrator for a sub-project. It runs targets::tar_make() in a clean, separate R process using callr to ensure the parent and child pipelines do not interfere with one another. After the sub-project completes successfully, it reads the specified result target and returns its value.

Author

Andrew G. Brown

Examples

if (FALSE) { # \dontrun{
# Example of a Hierarchical Workflow

# Assume you have two complex `targets` projects located at:
#   - "./study_site_A" (which produces a target called `final_model_fit`)
#   - "./study_site_B" (which also produces a target called `final_model_fit`)

# 1. Define the work units using the new helper function
work_to_do <- list(
  tarflowr_project(
    project_dir = "./study_site_A",
    result_target = final_model_fit,
    name = "site_A_run"
  ),
  tarflowr_project(
    project_dir = "./study_site_B",
    result_target = final_model_fit,
    name = "site_B_run"
  )
)

# 2. Define a function to combine the final results
combine_model_fits <- function(model_fit_list) {
  names(model_fit_list) <- sapply(model_fit_list, function(x) x$site_name)
  dplyr::bind_rows(model_fit_list, .id = "source_project")
}

# 3. Run the meta-orchestrator
all_fits <- tarflowr_run(
  work_units = work_to_do,
  process_func = run_targets_project, # Use the built-in function
  combine_func = combine_model_fits,
  project_dir = "_meta_analysis_project",
  packages = c("dplyr"), # Packages needed by combine_func
  workers = 2
)

print(all_fits)
} # }