Skip to content

Commit

Permalink
added future_apply
Browse files Browse the repository at this point in the history
  • Loading branch information
ljcolling committed Dec 19, 2023
1 parent 7045086 commit fd06414
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ Imports:
gginnards,
stats,
ggplot2,
rlang
rlang,
future.apply
Authors@R:
person(given = c("Lincoln", "John"),
family = "Colling",
Expand Down
14 changes: 2 additions & 12 deletions R/utils.r
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,15 @@ pmap <- function(x, f, ...) {

par_map <- function(x, f, ...) {
f <- match.fun(f)
# mclapply doesn't work on windows?
# dout <- parallel::mclapply(x, f, mc.cores = parallel::detectCores(), ...) # nolint
cl <- parallel::makeCluster(parallel::detectCores())
dout <- parallel::parLapply(cl, x, f, ...)
parallel::stopCluster(cl)
dout <- future.apply::future_lapply(x, f, ...)

Check warning on line 20 in R/utils.r

View check run for this annotation

Codecov / codecov/patch

R/utils.r#L20

Added line #L20 was not covered by tests
row.names(dout) <- NULL
dout
}

par_pmap <- function(x, f, ...) {
x_list <- unname(split(x, ~ row.names(x)))
f <- match.fun(f)
# dout <- parallel::mclapply(x_list, f,
# mc.cores = parallel::detectCores(), ...
# )

cl <- parallel::makeCluster(parallel::detectCores())
dout <- parallel::parLapply(cl, x_list, f, ...)
parallel::stopCluster(cl)
dout <- future.apply::future_lapply(x_list, f, ...)

Check warning on line 28 in R/utils.r

View check run for this annotation

Codecov / codecov/patch

R/utils.r#L28

Added line #L28 was not covered by tests
row.names(dout) <- NULL
Reduce(f = rbind, dout)
}
Expand Down

0 comments on commit fd06414

Please sign in to comment.