provides a clean, modern interface for running background parallel jobs using S7 classes, mirai daemons, and callr process management. Perfect for computationally intensive workflows that need robust error handling and progress monitoring.
You can install the development version of bakerrr from GitHub with:
# Install from GitHub
::pak("anirbanshaw24/bakerrr")
pak
# Or with devtools
::install_github("anirbanshaw24/bakerrr") devtools
# Define your function
<- function(x, y) {
compute_sum Sys.sleep(1) # Simulate work
+ y
x
}
# Create argument lists for each job
<- list(
args_list list(x = 1, y = 2),
list(x = 3, y = 4),
list(x = 5, y = 6),
list(x = 7, y = 8)
)
# Create and run bakerrr job
<- bakerrr::bakerrr(
job fun = compute_sum,
args_list = args_list,
n_daemons = 2
|>
) ::run_jobs(wait_for_results = TRUE)
bakerrr
# Check results
@results
job#> [[1]]
#> [1] 3
#>
#> [[2]]
#> [1] 7
#>
#> [[3]]
#> [1] 11
#>
#> [[4]]
#> [1] 15
#> [[1]] [1] 3
#> [[2]] [1] 7
#> [[3]] [1] 11
#> [[4]] [1] 15
print(job)
#> ✅ bakerrr
#> ├─ Status: COMPLETED
#> ├─ Function: compute_sum
#> ├─ Args: 4 sets
#> ├─ Daemons: 2
#> ├─ Cleanup: enabled
#> ├─ Process alive: FALSE
#> ├─ Result:
#> │ └─ List with 4 elements
# Function that may fail
<- function(x) {
risky_function if (x == "error") stop("Intentional error")
* 2
x
}
<- list(
args_list list(x = 5),
list(x = "error"), # This will fail gracefully
list(x = 10)
)
<- bakerrr::bakerrr(risky_function, args_list) |>
job ::run_jobs(wait_for_results = FALSE)
bakerrr@results
job#> [1] "sleeping"
#> [[1]] [1] 10
#> [[2]] [1] "Error in purrr::in_parallel: Intentional error"
#> [[3]] [1] 20
# Custom logging and process options
<- bakerrr::bakerrr(
job fun = compute_sum,
args_list = args_list,
bg_args = list(
stdout = "job_output.log",
stderr = "job_errors.log",
supervise = TRUE
)|>
) ::run_jobs(wait_for_results = FALSE) bakerrr
<- function() {
long_running_function Sys.sleep(5)
}# Start job without waiting
<- bakerrr::bakerrr(long_running_function, args_list) |>
job ::run_jobs(wait_for_results = FALSE)
bakerrr
# Check status later
summary(job)
#> Length Class1 Class2 Mode
#> 1 bakerrr::bakerrr S7_object object
#> ⏳ BackgroundParallelJob [running] - 4 daemons, 10 jobs
# Get results when ready
if (!job@bg_job_status$is_alive()) {
<- job@results
results }