[R] Reading in an XLS (really XML) file from website

Bos, Roger roger.bos at rothschild.com
Fri Feb 27 17:01:39 CET 2015


All,

I am trying to read the S&P 500 constituents from the iShares website using the following code:

   URL <- "http://www.ishares.com/us/239726/fund-download.dl"
   setInternet2(TRUE)
   download.file(url=URL, destfile="temp.xls")
   out <- readWorksheetFromFile(file="temp.xls", sheet="Holdings", header=TRUE, startRow=13)

R returns the following error:

>    out <- readWorksheetFromFile(file="temp.xls", sheet="Holdings", header=TRUE, startRow=13)
Error: IllegalArgumentException (Java): Your InputStream was neither an OLE2 stream, nor an OOXML stream
In addition: Warning message:
In download.file(url = URL, destfile = "temp.xls") :
  downloaded length 1938303 != reported length 200

Upon further examination this is because the format is really XML.  Is there any way to get XLConnect or any other excel reader to read in an XML file?  I thought XML was for new Excel format.

Barring that, can we read in the file using the XML package? I tried the following code...

   require(XML)
   tmp <- xmlParse(URL)

... but I get this error:

Opening and ending tag mismatch: Style line 14 and Style
Error: 1: Opening and ending tag mismatch: Style line 14 and Style

Thanks in advance for any help or hints,

Roger



***************************************************************
This message and any attachments are for the named person's use only.
This message may contain confidential, proprietary or legally privileged
information. No right to confidential or privileged treatment
of this message is waived or lost by an error in transmission.
If you have received this message in error, please immediately
notify the sender by e-mail, delete the message, any attachments and all
copies from your system and destroy any hard copies. You must
not, directly or indirectly, use, disclose, distribute,
print or copy any part of this message or any attachments if you are not
the intended recipient.




More information about the R-help mailing list