philchalmers / SimDesign

Structure for organizing Monte Carlo simulations in R
http://philchalmers.github.io/SimDesign/
61 stars 17 forks source link

Enable sending all output to one directory #8

Closed oguzhanogreden closed 6 years ago

oguzhanogreden commented 6 years ago

See https://github.com/oguzhanogreden/SimDesign/issues/3.

Experiencing that this is needed for a smooth experience while using one of the widely available computing infrastructure solutions in the Netherlands, I thought I'd suggest this here.

In case this will go through, following are needed:

  1. SimClean() needs to be adjusted.
  2. MPI may need adjustment, see analysis.R line 31.
philchalmers commented 6 years ago

Can you provide a simple example demonstrating this change? The concept itself seems fine to me, I'd just like to test it out before merging and documenting.

oguzhanogreden commented 6 years ago

Here it is.

You'll notice there's no check for whether the specified folder exists. Since there are safety checks in place, I considered it not relevant. a suppressWarnings() could be nice at line 750 here, otherwise there's a warning which may create a glitchy feeling.

Design <- expand.grid(mean_diff = seq(0, 1, by = .1), 
                      sample_size = c(10, 20, 30))

#--------------------------------------------------------------------

Generate <- function(condition, fixed_objects = NULL) {
    ret <- with(condition, rnorm(sample_size, mean_diff))
    ret
}

Analyse <- function(condition, dat, fixed_objects = NULL) {
    ret <- c(p = t.test(dat)$p.value)
    ret
}

Summarise <- function(condition, results, fixed_objects = NULL) {
    ret <- EDR(results, alpha = .05)
    ret
}

#--------------------------------------------------------------------

### Run the simulation (using all available cores)
results <- runSimulation(Design, replications=50, verbose=FALSE, parallel=TRUE,
                         generate=Generate, analyse=Analyse, summarise=Summarise, edit='none',
                         save = T, save_results = T, save_generate_data = T,
                         save_details = list(out_rootdir = '~/far_away'))
philchalmers commented 6 years ago

Thanks. This seems reasonable to me. Also note that dir.create() has a showWarnings flag to remove the warning you described. I'll merge this and add these components in when I document the change.