title: How to keep both keys after join with a named "by" in R
body: <p>With the dplyr join functions, you can use a named <code>by</code> if the join variables have different names. But the documentation warns "Note that only the key from the LHS is kept". How can I keep both keys?</p>
  
  <p>eg</p>
  
  <pre><code>library(dplyr)
  df1 &lt;- data.frame(name= c("Ann", "Betsy", "Charlie", "Dave"), 
    dob= c(as.Date("2000-01-01", "%Y-%m-%d"), 
          as.Date("2001-01-01", "%Y-%m-%d"), 
      as.Date("2002-01-01", "%Y-%m-%d"), as.Date("2003-01-01", "%Y-%m-%d")),
           stringsAsFactors=FALSE)
  
  df2 &lt;- data.frame(name= c("Ann", "Charlie", "Elmer", "Fred"), 
        date_birth= c(as.Date("2000-01-01", "%Y-%m-%d"), 
          as.Date("2004-01-01", "%Y-%m-%d"), 
          as.Date("2001-01-01", "%Y-%m-%d"),
  as.Date("2006-01-01", "%Y-%m-%d")), stringsAsFactors=FALSE)
  </code></pre>
  
  <p>Joining:</p>
  
  <pre><code> inner_join(df1, df2, by = c("name","dob" = "date_birth"))
  
       #  name    dob
       #  Ann     2000-01-01
  </code></pre>
  
  <p>How do I keep the dob and date_birth columns?</p>