The {bakerrr}
S7 class enables efficient background and
parallel job orchestration in R, making it easy to apply a function to
multiple sets of arguments using configurable daemons. This vignette
demonstrates usage with sample inputs and inspects job status and
results.
Define a simple function and generate a list of argument sets, introducing a mix of numeric and non-numeric (error-producing) cases.
fun <- function(x, y) {
Sys.sleep(2)
x + y
}
# Note how each list item is a set of arguments for the function above.
args_list <- list(
list(x = ceiling(rnorm(1) * 10), y = ceiling(rnorm(1) * 10)),
list(x = "p", y = ceiling(rnorm(1) * 10)), # Intentional type error
list(x = ceiling(rnorm(1) * 10), y = ceiling(rnorm(1) * 10)),
# Add more sets as needed
list(x = ceiling(rnorm(1) * 10), y = ceiling(rnorm(1) * 10)),
list(x = ceiling(rnorm(1) * 10), y = ceiling(rnorm(1) * 10)),
list(x = ceiling(rnorm(1) * 10), y = ceiling(rnorm(1) * 10)),
list(x = ceiling(rnorm(1) * 10), y = ceiling(rnorm(1) * 10)),
list(x = ceiling(rnorm(1) * 10), y = ceiling(rnorm(1) * 10)),
list(x = ceiling(rnorm(1) * 10), y = ceiling(rnorm(1) * 10)),
list(x = ceiling(rnorm(1) * 10), y = ceiling(rnorm(1) * 10))
)
Instantiate a bakerrr object and process jobs in parallel with configurable daemon count.
Print job summary and view results. Note that jobs triggering errors report the error messages as designed.
print(new_stirr)
#>
#> ✅ bakerrr
#> ├─ Status: COMPLETED
#> ├─ Functions:
#> [01] function (x, y) { Sys.sleep(2) x + y }
#> [02] function (x, y) { Sys.sleep(2) x + y }
#> [03] function (x, y) { Sys.sleep(2) x + y }
#> [04] function (x, y) { Sys.sleep(2) x + y }
#> [05] function (x, y) { Sys.sleep(2) x + y }
#> [06] function (x, y) { Sys.sleep(2) x + y }
#> [07] function (x, y) { Sys.sleep(2) x + y }
#> [08] function (x, y) { Sys.sleep(2) x + y }
#> [09] function (x, y) { Sys.sleep(2) x + y }
#> [10] function (x, y) { Sys.sleep(2) x + y }
#> ├─ Args: 10 sets
#> ├─ Daemons: 4
#> ├─ Cleanup: enabled
#> ├─ Process alive: FALSE
#> ├─ Result:
#> └─ List with 10 elements
new_stirr@results
#> [[1]]
#> [1] -1
#>
#> [[2]]
#> Error in purrr::in_parallel: non-numeric argument to binary operator
#>
#> [[3]]
#> [1] -1
#>
#> [[4]]
#> [1] 3
#>
#> [[5]]
#> [1] -4
#>
#> [[6]]
#> [1] 22
#>
#> [[7]]
#> [1] -29
#>
#> [[8]]
#> [1] 11
#>
#> [[9]]
#> [1] -3
#>
#> [[10]]
#> [1] 13