title: Rename variables via lookup table in R
body: <p>I have a dataframe in a certain order:</p>
  
  <pre><code>df &lt;- 
    data.frame(
      foo = 1:3,
      bar = LETTERS[1:3],
      baz = rnorm(3)
    )
  
  df
  
    foo bar         baz
  1   1   A  0.41474174
  2   2   B -0.08416768
  3   3   C -0.27931232
  </code></pre>
  
  <p>In another dataframe, I have the old variable names matched to some new names, but in a <strong><em>different order</em></strong>:</p>
  
  <pre><code>variable_match &lt;- 
    data.frame(
      old = names(df)[c(2, 3, 1)], 
      new = LETTERS[1:3]
    )
  
  variable_match
    old new
  1 bar   A
  2 baz   B
  3 foo   C
  </code></pre>
  
  <p>My question is: How do I rename the variables in the original dataframe by looking up the corresponding value in the second dataframe. I'm ideally looking for a <code>tidyverse</code> solution. I have tried variations of:</p>
  
  <pre><code>library(tidyverse)
  
  df %&gt;% rename_at(variable_match$old, funs(variable_match$new))
  </code></pre>
  
  <p>assuming that rename_at would be the right approach, but this doesn't work. I'm wondering if <code>purrr::map_*</code> would be the right approach, but can't see how. Many thanks for your suggestions.</p>