title: R: Download historical data from Yahoo Finance
body: <p>Yahoo Finance recently changed its historical data URLs from http to https. For example, here is the URL to obtain the maximum history for IBM (as of today, 2017-05-29):</p>
  
  <pre><code>https://query1.finance.yahoo.com/v7/finance/download/IBM?period1=-252345600&amp;period2=1496041200&amp;interval=1d&amp;events=history&amp;crumb=jIIyoewBT2o
  </code></pre>
  
  <p>When I try to read this resource from within R I get the following:</p>
  
  <pre><code>&gt; url = 'https://query1.finance.yahoo.com/v7/finance/download/IBM?period1=-252345600&amp;period2=1496041200&amp;interval=1d&amp;events=history&amp;crumb=jIIyoewBT2o'
  &gt; read.csv(url)
  Error in file(file, "rt") : 
    (converted from warning) cannot open URL 'https://query1.finance.yahoo.com/v7/finance/download/IBM?period1=-252345600&amp;period2=1496041200&amp;interval=1d&amp;events=history&amp;crumb=jIIyoewBT2o': HTTP status was '401 Unauthorized'
  </code></pre>
  
  <p>The download works fine when invoked manually through the browser, so it's not like Yahoo Finance is trying to prevent access to the data. Evidently, the browser is sending some secret sauce to the Yahoo server. Can I send the same secret sauce through an R script?</p>