title: Piping in R :: Passing specific vector elements when feeding next function's arguments
body: <p>Using piping in R (with <code>%&gt;%</code>), how can one pass <em>specific</em> vector elements from a function's output to feed the next function's arguments?</p>
  
  <p>I've tried using the dot operator with position in braces (i.e., <code>.[1], .[2]</code>) to no avail.</p>
  
  <p>The only way that was working for me was with <code>sapply()</code>, but I'm wondering whether there's a simpler solution I'm missing.</p>
  
  <h2>Example</h2>
  
  <pre class="lang-r prettyprint-override"><code>#I have a vector containing a sequence of numbers, with some duplicates and gaps, 
  #and I want to use its start and end points to create an analogous consecutive sequence.
  
  original_sequence &lt;- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 
  13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 
  28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 
  43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 
  58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 
  73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87,
  88, 89, 90, 91, 92, 93, 94, 95, 96, 98, 98, 99, 100, 101, 
  102, 103, 104, 105, 106, 107, 108, 109, 110)
  
  ## unsuccessful attempt #1
  original_sequence %&gt;%
     range() %&gt;% 
     seq()
  [1] 1 2 ## this result is equivalent to the output of `seq(2)`, 
          ## but what I want is to compute `seq(1 ,110)`.
  
  
  ## unsuccessful attempt #2
  original_sequence %&gt;%
     range() %&gt;% 
     seq(.[1]), .[2])
  
  Error: unexpected ',' in:
  "    range() %&gt;% 
      seq(.[1]),"
  
  ## attempt #3: somewhat successful but I wonder whether there's a better way
  original_sequence %&gt;%
     range() %&gt;% 
     sapply(., seq)
  
  [[1]]
  [1] 1
  
  [[2]]
    [1]   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38
   [39]  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76
   [77]  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108 109 110
  </code></pre>
  
  <p>Bottom line -- I was able to do it with <code>sapply</code> but I hope to figure out a solution in the spirit of my second attempt, because it's more handy to know a universal way to cherry-pick the specific vector elements you want to pass to the next function's arguments.</p>