2

I am getting errors whenever I'm using all forms of getSymbols and get.hist.quote commands. The error is basically:

>getSymbols("AAPL") 
Error in read.table(file = file, header = header, sep = sep, quote = quote, : 
  more columns than column names 

Another example:

    >x <- get.hist.quote(instrument = "^gspc", start = "1998-01-01", quote = "Close") 
    trying URL 'http://chart.yahoo.com/table.csv?s=^gspc&a=0&b=01&c=1998&d=4&e=12&f=2013&g=d&q=q&y=0&z=^gspc&x=.csv' 
    Content type 'text/csv' length unknown 
    opened URL 
    downloaded 230 Kb 

Error in read.table(destfile, header = TRUE, sep = ",", as.is = TRUE,  : 
  more columns than column names

It is happening with all sources and symbols. How do i fix it?? By the way the same commands are working just fine on other computers. Packages Used: "quantmod" or "tseries"

After running the debugger suggested in the comments i got:

> debugonce(read.table)
> getSymbols("AAPL")

Browse[2]> head(readLines(file))
[1] "000fe47"                                               
[2] "Date,Open,High,Low,Close,Volume,Adj Close"             
[3] "2013-05-13,451.51,457.90,451.50,454.74,11319600,454.74"
[4] "2013-05-10,457.97,459.71,450.48,452.97,11948800,452.97"
[5] "2013-05-09,459.81,463.00,455.58,456.77,14231700,456.77"
[6] "2013-05-08,459.04,465.37,455.81,463.84,16878500,460.79"
Browse[2]> tail(readLines(file))
[1] "2007-01-05,85.77,86.20,84.40,85.05,29812200,83.26"
[2] "2007-01-04,84.05,85.95,83.82,85.66,30259300,83.86"
[3] "2007-01-03,86.29,86.58,81.90,83.80,44225700,82.04"
[4] ""                                                 
[5] "0"                                                
[6] ""                                                 

Browse[2]> Q
> 
flodel
  • 87,577
  • 21
  • 185
  • 223
robmwd
  • 21
  • 2
  • 2
    A question containing "I want" and "Urgent" is very unlikely to be answered. – Eugen Rieck May 13 '13 at 23:39
  • Given the misformattings and punctuation issues, I'm surprised this made it past the [recently tightened quality control filter](http://meta.stackexchange.com/questions/174097/is-it-time-to-tighten-up-the-question-quality-filter/176875#176875)... – David Robinson May 13 '13 at 23:46
  • 1
    `get.hist.quote` belongs to `tseries` package. The OP should give this info. – Jilber Urbina May 13 '13 at 23:49
  • sorry for the bad post but its my first time posting and i want this problem solved because i need it for a project – robmwd May 13 '13 at 23:51
  • 1
    Guys, calm down, he has 1 rep, it is his first post. robmwd, as it works on one computer but doesn't on another you should post the `sessionInfo()` output from the two machines you are comparing. Also try and give a fully reproducible example. See here for what that means: http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Darren Cook May 13 '13 at 23:51
  • 1
    Thanks a lot Darren but nothing is clear regarding this problem. any example of getting stock information online using the r commands (getSymbols) or (get.hist.quote) results in the Error in read.table i don't know why it used to work a couple of days ago – robmwd May 13 '13 at 23:56
  • 1
    please run `sessionInfo()` and copy+paste the output – Ricardo Saporta May 14 '13 at 00:04
  • Running the following and showing us the output might be useful: Run 1) `debugonce(read.table)` 2) `getSymbols("AAPL")` 3) as you enter the debugger, run `head(readLines(file))` and `tail(readLines(file))` and show us what you get. 4) exit the debugger by typing `Q` then . – flodel May 14 '13 at 00:07
  • @flodel I ran the debugger you suggested and i posted the output in my original question i couldn't understand anything out of the output so thanks in advance for any help – robmwd May 14 '13 at 00:24
  • Thanks. Can you try the following: `head(readLines("http://chart.yahoo.com/table.csv?s=^gspc&a=0&b=01&c=1998&d=4&e=12&f=2013&g=d&q=q&y=0&z=^gspc&x=.csv"))` and tell us if it gives you a weird header like you had (`"000fe47"`)? Normally, the top row should be the header `"Date,Open,High,Low,Close,Volume,Adj Close"`. – flodel May 14 '13 at 00:39
  • @flodel I ran the command and the header it gave me is ("000fe60") – robmwd May 14 '13 at 00:45
  • Well, that proves the problem is not with the packages you use or `read.table`, but with more *basic* things since the data you download from the internet is corrupted. I'd recommend you start by re-installing R. Oh, and last thing, can you try to paste `http://chart.yahoo.com/table.csv?s=%5Egspc&a=0&b=01&c=1998&d=4&e=12&f=2013&g=d&q=q&y=0&z=%5Egspc&x=.csv` in your internet browser? If you still see `"000fe60"` at the top, it might be a more serious issue with your operating system or something to the like. – flodel May 14 '13 at 00:50
  • @flodel i actually uninstalled R. and deleted all packages and everything which has to do with R and then I re-installed it before posting this thread, and it didn't work. Is this the first time you see such problem?? – robmwd May 14 '13 at 00:53
  • Would you mind following that discussion here: http://chat.stackoverflow.com/rooms/25312/r-public? Thanks. – flodel May 14 '13 at 01:00
  • @flodel I tried the URL you gave me and the results had a perfectly normal header (Date, etc...) By the way this is only happening with stocks, for example (getFX) is working normally for currencies – robmwd May 14 '13 at 01:00
  • @flodel sorry i cant join the chat room because i have no reputation points. I am not behind a firewall, and it is working on another pc which is connected to the same network I also tried using google finance instead, also the same error occured – robmwd May 14 '13 at 01:02

1 Answers1

-2

Thx for your question. I can't reproduce the error though. My file downloads properly and read well.

my_file <- read.csv('http://chart.yahoo.com/table.csv s=^gspc&a=0&b=01&c=1998&d=4&e=12&f=2013&g=d&q=q&y=0&z=^gspc&x=.csv')
Guillaume
  • 1,277
  • 2
  • 13
  • 21