Skip to content

Commit a3fc584

Browse files
author
jasenfinch
committed
readFiles now uses the furrr package for parallel processing. Updated readFiles documentation future::plan now reexported
1 parent f9423ff commit a3fc584

7 files changed

+55
-39
lines changed

DESCRIPTION

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ Imports:
2121
lubridate,
2222
ggplot2,
2323
ggthemes,
24-
yaml
24+
yaml,
25+
future,
26+
furrr
2527
License: GPL-3
2628
Encoding: UTF-8
2729
RoxygenNote: 7.1.1

NAMESPACE

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export(binneRlyse)
66
export(detectClusterType)
77
export(detectInfusionScans)
88
export(detectParameters)
9+
export(plan)
910
export(plotChromFromFile)
1011
export(readBinningParameters)
1112
export(readFiles)
@@ -52,6 +53,8 @@ importFrom(dplyr,summarise)
5253
importFrom(dplyr,summarise_all)
5354
importFrom(dplyr,ungroup)
5455
importFrom(dplyr,vars)
56+
importFrom(furrr,future_map)
57+
importFrom(future,plan)
5558
importFrom(ggplot2,aes)
5659
importFrom(ggplot2,element_text)
5760
importFrom(ggplot2,facet_wrap)
@@ -85,7 +88,6 @@ importFrom(parallel,clusterExport)
8588
importFrom(parallel,detectCores)
8689
importFrom(parallel,makeCluster)
8790
importFrom(parallel,parLapply)
88-
importFrom(parallel,parLapplyLB)
8991
importFrom(parallel,stopCluster)
9092
importFrom(purrr,map)
9193
importFrom(purrr,map_chr)

R/getPeaks.R

+4-6
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55

66
sampProcess <- function(file,scans,dp){
77

8-
`%>%` <- getFromNamespace('%>%','magrittr')
9-
10-
pl <- binneR::getFile(file,scans) %>%
11-
dplyr::mutate(mz = round(mz,dp)) %>%
12-
dplyr::group_by(polarity,mz) %>%
13-
dplyr::summarise(intensity = sum(intensity)/length(scans))
8+
pl <- getFile(file,scans) %>%
9+
mutate(mz = round(mz,dp)) %>%
10+
group_by(polarity,mz) %>%
11+
summarise(intensity = sum(intensity)/length(scans))
1412

1513
return(pl)
1614
}

R/readFiles.R

+21-24
Original file line numberDiff line numberDiff line change
@@ -9,47 +9,44 @@
99
#' @param clusterType the type of cluster to use for parallel processing
1010
#' @return A list containing peak lists for the relevant scans with combined
1111
#' scan ranges for each present mode in the data file.
12+
#' @details
13+
#' Parallel processing is managed by the \code{future} package. This can be specified using the \code{plan() function}. See the example below and \code{?future::plan} for details on how this can be specified.
1214
#' @author Jasen Finch
13-
#' @importFrom parallel makeCluster parLapplyLB stopCluster
15+
#' @examples
16+
#' ## Example file path
17+
#' file_paths <- metaboData::filePaths('FIE-HRMS',
18+
#' 'BdistachyonEcotypes')[1]
19+
#'
20+
#' ## Optionally use declare parallel processing options
21+
#' plan(future::multisession,workers = 2)
22+
#'
23+
#' ## Process example file
24+
#' res <- readFiles(file_paths,
25+
#' dp = 2,
26+
#' scans = 6:17)
27+
#' @importFrom furrr future_map
1428
#' @importFrom dplyr bind_rows
1529
#' @importFrom tidyr spread
16-
#' @examples
17-
#' res <- readFiles(
18-
#' metaboData::filePaths('FIE-HRMS',
19-
#' 'BdistachyonEcotypes')[1],
20-
#' dp = 2,
21-
#' scans = 6:17)
2230
#' @export
2331

2432
readFiles <- function(files,
2533
dp,
26-
scans,
27-
nCores = 1,
28-
clusterType = detectClusterType()){
29-
30-
clust <- makeCluster(nCores, type = clusterType)
34+
scans){
3135

32-
clusterExport(clust, 'sampProcess')
33-
34-
pl <- parLapplyLB(clust,
35-
files,
36-
fun = sampProcess,
36+
pl <- future_map(files,
37+
sampProcess,
3738
scans = scans,
3839
dp = dp) %>%
3940
set_names(files) %>%
4041
bind_rows(.id = 'file') %>%
4142
mutate(mz = str_c(polarity,mz)) %>%
4243
split(.$polarity) %>%
43-
parLapplyLB(cl = clust,function(x){
44-
45-
`%>%` <- getFromNamespace('%>%','magrittr')
44+
future_map(~{
4645

47-
x <- spread(x,key = 'mz',value = 'intensity',fill = 0) %>%
46+
.x %>%
47+
spread(key = 'mz',value = 'intensity',fill = 0) %>%
4848
ungroup() %>%
4949
select(-file,-polarity)
50-
51-
return(x)
5250
})
53-
stopCluster(clust)
5451
return(pl)
5552
}

R/reexports.R

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
#' @rdname reexports
22
#' @export
3-
magrittr::`%>%`
3+
magrittr::`%>%`
4+
5+
#' @rdname reexports
6+
#' @importFrom future plan
7+
#' @export
8+
future::plan

man/readFiles.Rd

+15-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/reexports.Rd

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)