Using httr package, setting a header where the header name is a variable
<p>I want to set a header in an request using the R httr package and set a header, when I have the name of the header in a variable.</p>

<p>I would like to do something like this:</p>

<pre><code>tokenName = 'X-Auth-Token'

get_credentials_test &lt;- function (token) {

  url &lt;- paste(baseUrl,"/api/usercredentials", sep = '')
  r &lt;- GET(url, add_headers(tokenName = token))
  r
}
</code></pre>

<p>however, the above code seems to set a header with the name tokenName.</p>

<p>It does work if I do the following:</p>

<pre><code>get_credentials_test &lt;- function (token) {

   url &lt;- paste(baseUrl,"/api/usercredentials", sep = '')
   r &lt;- GET(url, add_headers('X-Auth-Token' = token))
   r
}
</code></pre>

<p>but I want to have some flexibility if the name of the header changes and the requirement to add the header is sprinkled liberally around the code.  I am not sure if it is possible to add a header contained with a variable but that is what I would like to do.</p>