Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If the simulation function always takes the same set of arguments, then Ramnath's approach of storing them in a data frame is best. For the more general case of variable inputs to <code>mySimulation</code>, you should store each set of inputs in a list &ndash; probably using a list of lists for running several simluations.</p> <p>The idea behind your <code>createParms</code> function looks sound; you can simplify the code a little bit.</p> <pre><code>createParms &lt;- function(model = "default", ...) { #default case parms &lt;- list( parm1 = 0, parm2 = 0 ) #other special cases if(model == "mymodel") { parms &lt;- within(parms, { parm1 &lt;- 1 parm2 &lt;- 2 }) } #overwrite from ... dots &lt;- list(...) parms[names(dots)] &lt;- dots parms } </code></pre> <p>Test this with, e.g.,</p> <pre><code>createParms() createParms("mymodel") createParms("mymodel", parm2 = 3) </code></pre> <p><code>do.call</code> may come in handy for running your simulation, as in</p> <pre><code>do.call(mySimulation, createParms()) </code></pre> <hr> <p>EDIT: What <code>do.call</code> does for you</p> <p>If you have <code>parms &lt;- createParms()</code>, then </p> <pre><code>do.call(mySimulation, parms) </code></pre> <p>is the same as</p> <pre><code>with(parms, mySimulation(parm1, parm2)) </code></pre> <p>The main advantage is that you don't need to spell out each parameter that you are passing into <code>mySimulation</code> (or to modify that function to accept the parameters in list form).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload