Skip to content

Commit

Permalink
future.apply
Browse files Browse the repository at this point in the history
  • Loading branch information
gravesti committed Sep 30, 2024
1 parent 06ca118 commit ed51c9d
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 4 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ Imports:
rstan (>= 2.26.0),
rstantools (>= 2.1.1),
R6,
assertthat
assertthat,
future.apply
LinkingTo:
BH (>= 1.66.0),
Rcpp (>= 0.12.0),
Expand Down
6 changes: 3 additions & 3 deletions R/analyse.R
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ analyse <- function(imputations, fun = ancova, delta = NULL, ...) {
)
}

results <- lapply(
imputations$imputations,
function(x, ...) {
results <- future.apply::future_lapply(
X = imputations$imputations,
FUN = function(x, ...) {
dat2 <- extract_imputed_df(x, imputations$data, delta)
fun(dat2, ...)
},
Expand Down
56 changes: 56 additions & 0 deletions vignettes/quickstart.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -411,3 +411,59 @@ poolObj <- pool(
alternative = "two.sided"
)
```


```{r, eval = FALSE}
library(future)
library(lubridate)
some_fun <- function(data) {
Sys.sleep(.5)
as_datetime(2)
NULL
}
my_fun <- function(
data,
vars,
visits = NULL,
weights = c("counterfactual", "equal", "proportional_em", "proportional")
) {
some_fun(data)
ancova(data, vars, visits, weights)
}
plan("multisession", workers = 4)
system.time({
anaObj_par <- analyse(
imputeObj,
my_fun,
vars = set_vars(
subjid = "PATIENT",
outcome = "CHANGE",
visit = "VISIT",
group = "THERAPY",
covariates = c("BASVAL")
)
)
anaObj_par
})
plan("sequential")
system.time({
anaObj_seq <- analyse(
imputeObj,
my_fun,
vars = set_vars(
subjid = "PATIENT",
outcome = "CHANGE",
visit = "VISIT",
group = "THERAPY",
covariates = c("BASVAL")
)
)
anaObj_seq
})
identical(anaObj_par, anaObj_seq)
```

0 comments on commit ed51c9d

Please sign in to comment.