Movatterモバイル変換


[0]ホーム

URL:


bakerrr ⏲️

CRANR-CMD-checkLintR-checkSpell-checkTest coverageCodecov

ElegantS7-based parallel job orchestration for R

{bakerrr} provides a clean, modern interface for running backgroundparallel jobs using S7 classes, mirai daemon(s), and callr processmanagement. Perfect for computationally intensive workflows that needrobust error handling and progress monitoring.

Features

Installation

You can install the development version of bakerrr fromCRAN with:

install.packages("bakerrr")

Quick Start

# Define your functioncompute_sum<-function(x, y) {Sys.sleep(1)# Simulate work  x+ y}# Create argument lists for each jobargs_list<-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 jobjob<- bakerrr::bakerrr(fun = compute_sum,args_list = args_list,n_daemons =2)|>  bakerrr::run_jobs(wait_for_results =TRUE)# Check resultsjob@results#> [[1]]#> [1] 3#>#> [[2]]#> [1] 7#>#> [[3]]#> [1] 11#>#> [[4]]#> [1] 15print(job)#>    [01] function (x, y) { Sys.sleep(1) x + y }#>    [02] function (x, y) { Sys.sleep(1) x + y }#>    [03] function (x, y) { Sys.sleep(1) x + y }#>    [04] function (x, y) { Sys.sleep(1) x + y }

Advanced Usage

Error Handling

# Function that may failrisky_function<-function(x) {if (x=="error")stop("Intentional error")  x*2}args_list<-list(list(x =5),list(x ="error"),# This will fail gracefullylist(x =10))job<- bakerrr::bakerrr(risky_function, args_list)|>  bakerrr::run_jobs(wait_for_results =FALSE)job@results#> [1] "running"#> [[1]] [1] 10#> [[2]] [1] "Error in purrr::in_parallel: Intentional error"#> [[3]] [1] 20

Background Job Arguments

# Custom logging and process optionscompute_sum<-function(x, y) {Sys.sleep(1)# Simulate work  x+ y}# Create argument lists for each jobargs_list<-list(list(x =1,y =2),list(x =3,y =4),list(x =5,y =6),list(x =7,y =8))job<- bakerrr::bakerrr(fun = compute_sum,args_list = args_list,bg_args =list(stdout ="job_output.log",stderr ="job_errors.log",supervise =TRUE  ))|>  bakerrr::run_jobs(wait_for_results =FALSE)

Asynchronous Execution

long_running_function<-function() {Sys.sleep(5)}# Start job without waitingjob<- bakerrr::bakerrr(long_running_function, args_list)|>  bakerrr::run_jobs(wait_for_results =FALSE)# Check status latersummary(job)#>           Length           Class1           Class2             Mode#>                1 bakerrr::bakerrr        S7_object           object#> ⏳ BackgroundParallelJob [running] - 4 daemon(s), 10 jobs# Get results when readyif (!job@bg_job_status$is_alive()) {  results<- job@results}

MultipleFunctions in Parallel and in Background

You can run multiple different functions, each with their ownarguments, in parallel background jobs using {bakerrr}. Just supply alist of functions and a matching list of argument sets:

# List of functions with different logicfun_list<-list(function(x, y) x+ y,function(x, y) x* y,function(x, y) x- y,function(x, y) x/ y,function(x, y) x^y,function(x, y) x%% y,function(x, y)paste0(x,"-", y),function(x, y)mean(c(x, y)),function(x, y)max(x, y),function(x, y)min(x, y))# Corresponding list of argument setsset.seed(1)args_list<-list(list(x =3,y =6),list(x ="p",y =2),# type errorlist(x =5,y =8),list(x =10,y =2),list(x =2,y =5),list(x =13,y =4),list(x ="A",y =7),# type errorlist(x =6,y =9),list(x =3,y =4),list(x =1,y =2))# Run jobs in paralleljob<- bakerrr::bakerrr(fun = fun_list,args_list = args_list,n_daemons =4)|> bakerrr::run_jobs(wait_for_results =TRUE)# Inspect results and statusjob@results#> [[1]]#> [1] 9#>#> [[2]]#> Error in purrr::in_parallel: non-numeric argument to binary operator#>#> [[3]]#> [1] -3#>#> [[4]]#> [1] 5#>#> [[5]]#> [1] 32#>#> [[6]]#> [1] 1#>#> [[7]]#> [1] "A-7"#>#> [[8]]#> [1] 7.5#>#> [[9]]#> [1] 4#>#> [[10]]#> [1] 1print(job)#>    [01] function (x, y) x + y#>    [02] function (x, y) x * y#>    [03] function (x, y) x - y#>    [04] function (x, y) x/y#>    [05] function (x, y) x^y#>    [06] function (x, y) x%%y#>    [07] function (x, y) paste0(x, "-", y)#>    [08] function (x, y) mean(c(x, y))#>    [09] function (x, y) max(x, y)#>    [10] function (x, y) min(x, y)summary(job)#>           Length           Class1           Class2             Mode#>                1 bakerrr::bakerrr        S7_object           objectbakerrr::status(job)#> [1] "done"

Performance Tips

Dependencies

Further Help &Documentation

Troubleshooting

Citation

citation("bakerrr")#> To cite package 'bakerrr' in publications use:#>#>   Shaw A (2025). _bakerrr: Background-Parallel Jobs_. R package version#>   0.2.0, <https://github.com/anirbanshaw24/bakerrr>.#>#> A BibTeX entry for LaTeX users is#>#>   @Manual{,#>     title = {bakerrr: Background-Parallel Jobs},#>     author = {Anirban Shaw},#>     year = {2025},#>     note = {R package version 0.2.0},#>     url = {https://github.com/anirbanshaw24/bakerrr},#>   }

[8]ページ先頭

©2009-2025 Movatter.jp