title: How to use magrittr piping with multi-argument functions?
body: <p>For single argument functions, it is reasonably trivial to translate "standard" R code to the <a href="https://github.com/smbache/magrittr" rel="noreferrer"><code>magrittr</code></a> pipe style.</p>
  
  <pre><code>mean(rnorm(100))
  </code></pre>
  
  <p>becomes</p>
  
  <pre><code>rnorm(100) %&gt;% mean
  </code></pre>
  
  <p>For multi-argument functions, it isn't clear to me what the best way to proceed is.  There are two cases.  </p>
  
  <p>Firstly, the case when additional arguments are constants.  In this case, you can create an anonymous function which changes the constant values.  For example:</p>
  
  <pre><code>mean(rnorm(100), trim = 0.5)
  </code></pre>
  
  <p>becomes</p>
  
  <pre><code>rnorm(100) %&gt;% (function(x) mean(x, trim = 0.5))
  </code></pre>
  
  <p>Secondly, the case where multiple vector arguments are required.  In this case, you can combine inputs into a list, and create an anonymous function that operates on list elements.</p>
  
  <pre><code>cor(rnorm(100), runif(100))
  </code></pre>
  
  <p>becomes</p>
  
  <pre><code>list(x = rnorm(100), y = runif(100)) %&gt;% (function(l) with(l, cor(x, y)))  
  </code></pre>
  
  <p>In both cases my solutions seem clunky enough that I feel like I'm missing a better way to do this.  How should I pipe multiple arguments to functions?</p>