Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved power2 via furrr #15

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ Imports:
magrittr,
flipr,
cli,
withr
withr,
progress,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do you use the progress package?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As commented before:

I have updated DESCRIPTION file importing progressr and furrr. However, checks report:

Error: Error in loadNamespace(x) : there is no package called 'progress'

I do not explicitly use progress, should I add this package to "Imports" in DESCRIPTION file?

I solve errors by adding the progress package in DESCRIPTION file, but I do not use it explicitly.

progressr,
furrr
RoxygenNote: 7.1.2
Roxygen: list(markdown = TRUE)
URL: https://astamm.github.io/nevada/, https://github.com/astamm/nevada/
Expand Down
60 changes: 34 additions & 26 deletions R/simulations.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,32 +56,40 @@ power2 <- function(model1 = "gnp", model2 = "k_regular",
if (!is.null(seed))
withr::local_seed(seed)

pvalues <- replicate(
R,
test2_global(
x = nvd(
model = model1,
n = n1,
num_vertices = num_vertices,
model_params = model1_params,
seed = NULL
),
y = nvd(
model = model2,
n = n2,
num_vertices = num_vertices,
model_params = model2_params,
seed = NULL
),
representation = representation,
distance = distance,
stats = stats,
B = B,
test = test,
k = k,
seed = 1234
)$pvalue
)
progressr::handlers(progressr::handler_progress(format="[:bar] :percent :eta :message"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The user defines these. Not us as package developers.


fun <- function(xs) {
p <- progressr::progressor(steps = xs)
pbfun <- function(dummy){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pbfun is not evocative as a name either...

p() #signal progress
test2_global(
x = nvd(
model = model1,
n = n1,
num_vertices = num_vertices,
model_params = model1_params,
seed = NULL
),
y = nvd(
model = model2,
n = n2,
num_vertices = num_vertices,
model_params = model2_params,
seed = NULL
),
representation = representation,
distance = distance,
stats = stats,
B = B,
test = test,
k = k,
seed = 1234
)$pvalue
}
y <- furrr::future_map_dbl(1:xs, pbfun, .options = furrr::furrr_options(seed = TRUE))
}

progressr::with_progress(pvalues <- fun(R))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here.
In addition, fun is not a good naming convention, nor is dummy.


mean(pvalues <= alpha)
}