title: How to assign from a function which returns more than one value?
body: <p>Still trying to get into the R logic...  what is the "best" way to unpack (on LHS) the results from a function returning multiple values?</p>
  
  <p>I can't do this apparently:</p>
  
  <pre><code>R&gt; functionReturningTwoValues &lt;- function() { return(c(1, 2)) }
  R&gt; functionReturningTwoValues()
  [1] 1 2
  R&gt; a, b &lt;- functionReturningTwoValues()
  Error: unexpected ',' in "a,"
  R&gt; c(a, b) &lt;- functionReturningTwoValues()
  Error in c(a, b) &lt;- functionReturningTwoValues() : object 'a' not found
  </code></pre>
  
  <p>must I really do the following?</p>
  
  <pre><code>R&gt; r &lt;- functionReturningTwoValues()
  R&gt; a &lt;- r[1]; b &lt;- r[2]
  </code></pre>
  
  <p>or would the R programmer write something more like this:</p>
  
  <pre><code>R&gt; functionReturningTwoValues &lt;- function() {return(list(first=1, second=2))}
  R&gt; r &lt;- functionReturningTwoValues()
  R&gt; r$first
  [1] 1
  R&gt; r$second
  [1] 2
  </code></pre>
  
  <p>--- edited to answer Shane's questions ---</p>
  
  <p>I don't really need giving names to the result value parts.  I am applying one aggregate function to the first component and an other to the second component (<code>min</code> and <code>max</code>.  if it was the same function for both components I would not need splitting them).  </p>