[R] importing excel-file

Alberto Monteiro albmont at centroin.com.br
Fri Apr 20 13:59:22 CEST 2007


Hans-Peter wrote:
> 
>> I can't call read.xls while Excel is opening the xls file.
>> R crashes and must be aborted.
> 
> Could not reproduce here (Win2000, Excel 2003, R 2.4.1 and
> 2.5.0.alpha). Who knows...
>
This is Windows XP, Excel 2003, R 2.4.1.

> but I cannot think of anything that could
> cause such a problem: xlsReadWrite works on the plain file (Excel is
> not even needed), doesn't lock the file and, if there were problems,
> handles eventual exceptions before leaving the DLL. If you have a
> reproducible test case I would be very interested in it.
>
Maybe the problem is with Windows XP. I know that it locks some
files, even when I open for reading. For example, if I open 'test.xls'
file, then I can't issue the DOS command 'copy test.xls new_test.xls'.
 
> ...but the following should make you happy too:
> 
> test9 <- read.xls( filename, sheet = "sheet name", rowNames = FALSE,
> dateTimeAs = "isodatetime" )
> 
I added colClasses = "double", and now it works - but I lose all
strings, that become NAs (they don't matter - maybe if they matter,
I just have to call read.xls twice). Without colClasses = "double", 
the numbers become meaningless stuff.

OTOH, the dates aren't rendered as dates in either case, but using
colClasses="double", they are something that be made into dates, with

  as.POSIXlt("1899-12-30", "GMT") + test9[100:120,1] * 86400

Alberto Monteiro



More information about the R-help mailing list