From 3dd2b609759d048d435fc9fbdf8f57b682995a63 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Todor=20Kondi=C4=87?= <todor.kondic@uni.lu>
Date: Mon, 17 Jun 2019 15:55:36 +0200
Subject: [PATCH] Extend sw.do to use parallel features

* R/run.R(sw.do): New argument.
  [proc]

* man/sw.do.Rd: Update docs.
---
 R/run.R      | 12 +++++++++---
 man/sw.do.Rd |  5 ++++-
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/R/run.R b/R/run.R
index 755d4e7..38f9a02 100644
--- a/R/run.R
+++ b/R/run.R
@@ -31,16 +31,22 @@ attch<-function(...) paste(...,sep='')
 ##' @param rdir The root data directory.
 ##' @param combine If TRUE, use combineMultiplicies to merge
 ##'     workspaces corresponding to different collisional energies.
+##' @param proc Split work between this amount of processes. If FALSE
+##'     (or, 1), run sequential.
 ##' @return A named list of msmsWorkspace objects.
 ##' @author Todor Kondić
 ##' @export
-sw.do<-function(fn_data,fn_cmpd_list,mode,rdir=".",combine=F) {
- 
+sw.do<-function(fn_data,fn_cmpd_list,mode,rdir=".",combine=F,proc=F) {
     no_drama_mkdir(rdir)
     wdirs<-sapply(basename(fn_data),function(nm) file.path(rdir,stripext(nm)))
     sapply(wdirs,no_drama_mkdir)
     stgs<-sapply(basename(wdirs),function (nm) paste(nm,"yml",sep='.'))
-    v(fn_data,stgs,wdirs,fn_cmpd_list,mode,combine=combine)
+    cl<-parallel::makeCluster(proc)
+    if (proc) {
+        p.sw(fn_data,stgs,wdirs,fn_cmpd_list,mode,combine=combine,cl=cl)
+    } else {
+        v(fn_data,stgs,wdirs,fn_cmpd_list,mode,combine=combine)
+    }
 }
 
 ##' Creates and prepares mbWorkspace objects before the full workflow
diff --git a/man/sw.do.Rd b/man/sw.do.Rd
index bb2a049..a025d6c 100644
--- a/man/sw.do.Rd
+++ b/man/sw.do.Rd
@@ -4,7 +4,7 @@
 \alias{sw.do}
 \title{Perform MassBank Workflow on Multiple Compound Mixtures}
 \usage{
-sw.do(fn_data, fn_cmpd_list, mode, rdir = ".", combine = F)
+sw.do(fn_data, fn_cmpd_list, mode, rdir = ".", combine = F, proc = F)
 }
 \arguments{
 \item{fn_data}{List of mzML data filenames to be processed.}
@@ -17,6 +17,9 @@ sw.do(fn_data, fn_cmpd_list, mode, rdir = ".", combine = F)
 
 \item{combine}{If TRUE, use combineMultiplicies to merge
 workspaces corresponding to different collisional energies.}
+
+\item{proc}{Split work between this amount of processes. If FALSE
+(or, 1), run sequential.}
 }
 \value{
 A named list of msmsWorkspace objects.
-- 
GitLab