Skip to content

Commit 868f620

Browse files
committed
Update runner.R
1 parent da88960 commit 868f620

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

R/runner.R

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,59 @@
1-
#' Invoke an analysis application
1+
#' @title Invoke an Analysis Application (Internal Function)
22
#'
3+
#' @description
4+
#' This internal function executes an analysis application after validating its dependencies.
5+
#' It handles application execution, error reporting, and performance profiling.
6+
#'
7+
#' @param app A list defining the analysis application. Must contain:
8+
#' - `name`: (character) Name of the application (for logging).
9+
#' - `call`: (function) The function to execute the application logic.
10+
#' - `profiler`: (list) Stores performance metrics (e.g., execution time).
11+
#' @param context A list or environment providing runtime context, such as input data paths,
12+
#' environment variables, or configuration settings required by the application.
13+
#'
14+
#' @return Invisibly returns `NULL`. The function primarily updates `app$profiler` with execution
15+
#' time metrics and may modify the `context` during execution.
16+
#'
17+
#' @details
18+
#' ### Key Steps:
19+
#' 1. ​**Dependency Check**:
20+
#' Validates if required context variables and files exist via `check_dependency(app, context)`.
21+
#' - If dependencies are met, proceeds to execute the application.
22+
#' - If dependencies are missing, throws an error with detailed missing resources.
23+
#'
24+
#' 2. ​**Execution**:
25+
#' - Logs start/end timestamps if `options(verbose = TRUE)`.
26+
#' - Executes `app$call` with arguments `app` and `context` using `do.call()`.
27+
#'
28+
#' 3. ​**Error Handling**:
29+
#' - Aggregates missing dependencies into readable error messages.
30+
#' - Calls `throw_err()` to terminate the workflow and report issues.
31+
#'
32+
#' 4. ​**Profiling**:
33+
#' Records total execution time in `app$profiler$time` using `time_span()` for human-readable formatting.
34+
#'
35+
#' @examples
36+
#' \dontrun{
37+
#' # Define a sample application
38+
#' app <- list(
39+
#' name = "demo_analysis",
40+
#' call = function(argv) {
41+
#' print(paste("Running:", argv$app$name))
42+
#' },
43+
#' profiler = list()
44+
#' )
45+
#'
46+
#' # Execute with context
47+
#' .internal_call(app, context = list())
48+
#' }
49+
#'
50+
#' @note
51+
#' - This is an internal function and not intended for direct use.
52+
#' - Error messages include:
53+
#' - Missing context variables (e.g., `dependency$context_env_missing`).
54+
#' - Missing files (e.g., `dependency$workfiles_missing`).
55+
#'
56+
#' @keywords internal
357
const .internal_call = function(app, context) {
458
# check of the app dependency
559
let dependency = check_dependency(app, context);

0 commit comments

Comments
 (0)