A second possibility (not as automated but very simple to do) is to read the first sheet with verbose = TRUE:
DF <- read.xls("test.xls", sheet = 1, verbose = TRUE) and it will display the number of sheets in a message. You can then read them in in a loop. On Thu, Jul 2, 2009 at 11:05 AM, Gabor Grothendieck<ggrothendi...@gmail.com> wrote: > If you are on Windows and have Excel on the same machine > then the code here: > > http://tolstoy.newcastle.edu.au/R/e6/help/09/03/7736.html > > will return the number of worksheets as well as a vector of > the worksheet names. > > It seems that the email has somehow caused some of the > lines to wrap so you will have to correct that. > > There is also some info on various methods of reading excel > spreadsheets here: > http://wiki.r-project.org/rwiki/doku.php?id=tips:data-io:ms_windows > > On Thu, Jul 2, 2009 at 10:22 AM, Lauri Nikkinen<lauri.nikki...@iki.fi> wrote: >> Hi, >> >> I'm trying to read several Excel sheets from an Excel file into a >> list. I'm using >> read.xls from package 'gdata'. I would like to know how I can >> check the number of sheets before the loop (in the example below) so >> that I could adjust the loop counter? Any suggestions? >> >> DF.list <- list() >> for (i in 1:4) { >> DF.list[[i]] <- read.xls("sample_file.xls", sheet=i, >> stringsAsFactors = FALSE) >> } >> >> Thanks, >> -L >> >> ______________________________________________ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.