title: Return object vector (e.g. list of variables) as character vector in R
body: <p>I would like to return an object vector (e.g. a list of variables) as a character vector in R. This is as close as I've gotten:</p>
  <pre><code>library(tidyverse)
  
  data &lt;- as_tibble(mtcars)
  
  foo &lt;- function (vars) {
    as.character(enexpr(vars))
  }
  
  foo(c(hp, drat, wt))
  </code></pre>
  <p>I would like this to return <code>[1] &quot;hp&quot;   &quot;drat&quot; &quot;wt&quot; </code> but instead I'm getting <code>[1] &quot;c&quot;    &quot;hp&quot;   &quot;drat&quot; &quot;wt&quot;</code>.</p>
  <p>The code below works but it seems inelegant (and requires reading in the data):</p>
  <pre><code>foo &lt;- function (vars) {
    names(select(data, {{ vars }}))
  }
  
  foo(c(hp, drat, wt))
  </code></pre>
  <p>The application is passing a selection of variables to a paste function so that they can be combined to make a formula.</p>
  <p><strong>Edit:</strong> It goes without saying, this would also obviously work:</p>
  <pre><code>foo &lt;- function (vars) {
    as.character(enexpr(vars))[-1]
  }
  
  foo(c(hp, drat, wt))
  </code></pre>
  <p>My feeling though is that there still must be a tidier (pun intended) way of doing this.</p>