title: Repeat R script multiple times
body: <p>I have an R script with hundreds of lines. This script eventually gives me a single numerical answer at the end. Now I want to create a confidence interval and hence run this whole script over and over multiple times to be able to calculate the mean and standard deviation. But I do not want to create a 'for' loop over the whole thing because that becomes really complicated </p>
  
  <p>After some research, I came across this method: </p>
  
  <p>My final answer is named as 'result' and then in a new script file,</p>
  
  <pre><code>result_list&lt;-lapply(1:10, function(n)source("my_script_file.R"))
  result_list
  </code></pre>
  
  <p>(repeating 10 times for example)</p>
  
  <p>However the final results looks like this,</p>
  
  <pre><code>[[1]]
  [[1]]$value
  [1] 136.9876
  
  [[1]]$visible
  [1] TRUE
  
  [[2]]
  [[2]]$value
  [1] 138.4969
  
  [[2]]$visible
  [1] TRUE
  
  [[3]]
  [[3]]$value
  [1] 0.2356484
  
  [[3]]$visible
  [1] TRUE
  
  . 
  .
  </code></pre>
  
  <p>Now I have no idea what the second line means in every iterations? And how do I get the list of values, <code>result_list$values</code> doesn't work, while also ignoring the too small values that could be simulation error as like the 3rd one in here to be able to calculate the mean and sd.</p>
  
  <p>Also Is there any other way to repeat this process except this method? </p>