title: Quantmod get/viewFinancials in Loop
body: <p>I would like to cycle through a list of tickers, get their financials and export them to CSV files in a folder on my desktop.  However, I have been having trouble with an error in R related to viewFinancials() in the Quantmod package.  The code and error are shown below.  </p>
  
  <p>And so, my question is how to assign a variable as an object of class financial so that my loop runs properly? Or if anyone has another alternative, I would be excited to hear it!</p>
  
  <p>Here is the error message:</p>
  
  <blockquote>
    <p>Error in viewFinancials(co.f, "BS", "Q") : 
     ‘x’ must be of type ‘financials’</p>
  </blockquote>
  
  <p>Here is the code I am working on:</p>
  
  <pre><code> tickers &lt;- c('AAPL','ORCL','MSFT')
  
   for(i in 1:length(tickers)){
  
       co &lt;- tickers[1]
       #co.f &lt;- paste(co,".f",sep='') #First attempt, was worth a try
  
       co.f &lt;- getFin(co, auto.assign=T)  # automatically assigns data to "co.f" object
       BS.q&lt;-viewFinancials(co.f,'BS',"Q")  # quarterly balance sheet
       IS.q&lt;-viewFinancials(co.f,"IS","Q")  # quarterly income statement
       CF.q&lt;-viewFinancials(co.f,"CF","Q")  # quarterly cash flow statement
       BS&lt;-viewFinancials(co.f,"BS","A")  # annual balance sheet
       IS&lt;-viewFinancials(co.f,"IS","A")  # annual income statement
       CF&lt;-viewFinancials(co.f,"CF","A")  # annual cash flow statement
  
       d&lt;-Sys.Date()
  
       combinedA &lt;- rbind(BS,IS,CF)
       combinedQ &lt;- rbind(BS.q,IS.q,CF.q)
  
       BSAfile &lt;- paste('/Users/dedwards/Desktop/RFinancials/',d,' ',co,'_BS_A.csv',sep='')
       BSQfile &lt;- paste('/Users/dedwards/Desktop/RFinancials/',d,' ',co,'_BS_Q.csv',sep='')
       write.csv(combinedA, file = BSAfile, row.names=TRUE)
       write.csv(combinedQ, file = BSQfile, row.names=TRUE)
  }
  </code></pre>