Skip to contents

Given a Method object or list of Method objects, this function runs the method(s) on the draws passed through object. The output of each method is saved to file.


run_method(object, methods, out_loc = "out", parallel = NULL)



an object of class DrawsRef (or a list of such objects) as returned by link{simulate_from_model}. If object is a Simulation, then function is applied to the referenced draws in that simulation and returns the same Simulation object but with references added to the new outputs created.


a list of Method and/or ExtendedMethod objects or a single Method or object ExtendedMethod


(optional) a length-1 character vector that gives location (relative to model's path) that method outputs are stored.This can be useful for staying organized when multiple simulations are based on the same Model and Draws objects.


either NULL or a list containing socket_names and (optionally) libraries and save_locally (see Details for more information)


This function creates objects of class Output and saves each to file (at dir/model_name/<out_loc>/r<index>_<method_name>.Rdata. If parallel is not NULL, then it must be a list containing socket_names, which can either be a positive integer specifying the number of copies to run on localhost or else a character vector of machine names (e.g., "mycluster-0-0"). The list parallel can also contain libraries, a character vector of R packages that will be needed on the slaves and save_locally, a logical that indicates whether the files generated should be saved on the slaves (i.e., locally) or on the master.

Before running each method on index i, the RNG state is restored to what it was at the end of calling simulate_from_model on this index. This is only relevant for randomized methods. The choice to do this ensures that one will get identical results regardless of the order in which methods and indices are run in. When ExtendedMethod objects are passed, these are run after all Method objects have been run. This is because each ExtendedMethod object depends on the output of its base method. Furthermore, before an ExtendedMethod is called, the RNG state is restored to what it was after the base method had been called.


if (FALSE) {
 # suppose previously we had run the following:
 sim <- new_simulation(name = "normal-example",
                       label = "Normal Mean Estimation",
                       dir = tempdir()) %>%
   generate_model(make_my_example_model, n = 20) %>%
   simulate_from_model(nsim = 50, index = 1:3)
 # then we could add
 sim <- run_method(sim, my_example_method)