title: R - generate all combinations from 2 vectors given constraints
body: <p>I would like to generate all combinations of two vectors, given two constraints: there can never be more than 3 characters from the first vector, and there must always be at least one characters from the second vector.  I would also like to vary the final number of characters in the combination.</p>
  
  <p>For instance, here are two vectors:</p>
  
  <pre><code>vec1=c("A","B","C","D")
  vec2=c("W","X","Y","Z")
  </code></pre>
  
  <p>Say I wanted 3 characters in the combination.  Possible acceptable permutations would be: <code>"A" "B" "X"</code>or <code>"A" "Y" "Z"</code>. An unacceptable permutation would be: <code>"A" "B" "C"</code> since there is not at least one character from <code>vec2</code>.</p>
  
  <p>Now say I wanted 5 characters in the combination.  Possible acceptable permutations would be: <code>"A" "C" "Z" "Y"</code> or <code>"A" "Y" "Z" "X"</code>. An unacceptable permutation would be: <code>"A" "C" "D" "B" "X"</code> since there are >3 characters from <code>vec2</code>.</p>
  
  <p>I suppose I could use <code>expand.grid</code> to generate all combinations and then somehow subset, but there must be an easier way.  Thanks in advance!</p>