Skip to content

Commit

Permalink
parameters fix
Browse files Browse the repository at this point in the history
  • Loading branch information
acoppock committed Jun 7, 2018
1 parent 7379b67 commit 8a8afd0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 33 deletions.
7 changes: 5 additions & 2 deletions R/simulate_design.R
Expand Up @@ -102,11 +102,15 @@ simulate_design <-
Map(cbind, design_ID = names(simulations_list), simulations_list, stringsAsFactors = FALSE)
}


# Cleanup
simulations_df <- rbind_disjoint(simulations_list)
rownames(simulations_df) <- NULL

# # Check that there are the expected number of simulations
#Obtain all parameters
attr(simulations_df, "parameters") <- names(rbind_disjoint(lapply(designs, function(x) attr(x, "parameters"))))

# Check that there are the expected number of simulations
# check_sim_number(simulations_df, sims)

simulations_df
Expand Down Expand Up @@ -182,7 +186,6 @@ simulate_single_design <-
as_list(attr(design, "parameters")),
simulations_df[, -1, drop = FALSE])
}

simulations_df

}
Expand Down
72 changes: 41 additions & 31 deletions tests/testthat/test-function-expand.R
Expand Up @@ -10,35 +10,45 @@ my_template <- function(N = 100,
my_design
}

# debugonce(DeclareDesign:::expand_design)
design_list <-
expand_design(
template = my_template,
N = c(c(20, 20, 20), c(20, 20, 20), c(20, 20, 20)),
my_estimand_func = c(mean, median)
)

design_list <-
expand_design(
template = my_template,
N = c(10, 50, 100),
my_estimand_func = c(mean, median)
)

design_list <-
expand_design(
template = my_template,
N = c(10, 50, 100),
my_estimand_func = list(mean, median)
)


design_list <-
expand_design(
template = my_template,
N = c(10, 50, 100),
my_estimand_func = mean
)



test_that("expand_design works",{

design_list <-
expand_design(
template = my_template,
N = c(c(20, 20, 20), c(20, 20, 20), c(20, 20, 20)),
my_estimand_func = c(mean, median)
)
diag <- diagnose_design(design_list, sims = 5, bootstrap_sims = FALSE)
expect_true(all(c("N", "my_estimand_func") %in% names(diag$diagnosands_df)))

design_list <-
expand_design(
template = my_template,
N = c(10, 50, 100),
my_estimand_func = c(mean, median)
)
diag <- diagnose_design(design_list, sims = 5, bootstrap_sims = FALSE)
expect_true(all(c("N", "my_estimand_func") %in% names(diag$diagnosands_df)))

design_list <-
expand_design(
template = my_template,
N = c(10, 50, 100),
my_estimand_func = list(mean, median)
)
diag <- diagnose_design(design_list, sims = 5, bootstrap_sims = FALSE)
expect_true(all(c("N", "my_estimand_func") %in% names(diag$diagnosands_df)))


design_list <-
expand_design(
template = my_template,
N = c(10, 50, 100),
my_estimand_func = mean
)

diag <- diagnose_design(design_list, sims = 5, bootstrap_sims = FALSE)
expect_true(all(c("N", "my_estimand_func") %in% names(diag$diagnosands_df)))

})

0 comments on commit 8a8afd0

Please sign in to comment.