title: Best way to return multiple modified arguments in R?
body: <p>I'm trying to write a function (or the best R alternative), given a <i>deck</i> vector and a <i>hand</i> vector, that takes the first element from the deck and adds it to the hand.</p>
  
  <pre><code># initialize the deck.  We don't care about suits, so modulus 13
  deck &lt;- sample(52, 52, replace = FALSE, prob = NULL) %% 13 + 1
  
  # initilize the hand
  hand &lt;- vector(mode="numeric", length=0)
  
  #deal a card from the deck to the hand.
  # it's these two lines I'd like to put in something like a function 
  #   and return the modified vectors
    phand &lt;- c(hand, deck[1])
    deck &lt;- deck[-1]
  </code></pre>
  
  <p>In something like Python, you might do it like this:</p>
  
  <pre><code>def dealcard(deck,hand)
  
     # do something to deck and hand
     return deck, hand
  
  deck,hand = dealcard(deck,hand)
  </code></pre>
  
  <p>Looking at the first answer to this:
  <a href="https://stackoverflow.com/questions/8419877/modify-variable-within-r-function">modify variable within R function</a></p>
  
  <blockquote>
    <p>There are ways as @Dason showed, but really - you shouldn't!</p>
    
    <p>The whole paradigm of R is to "pass by value". @Rory just posted the normal way to handle it - just return the modified value...</p>
  </blockquote>
  
  <p>So what is the most <i>R-thonic</i> way to accomplish this "modifying multiple arguments to a function"?</p>
  
  <p>I could see accomplishing something similar with a matrix where one column uses numbers to indicate which hand a row/card is dealt to, but it would make the code much less intuitive.  It's easy to imagine a function:</p>
  
  <pre><code>score &lt;- ScoreFunction(DealerHand)
  </code></pre>
  
  <p>vs.:</p>
  
  <pre><code>score &lt;- ScoreFunction(DeckMatrix, 1)
  </code></pre>