[R-gregmisc-users] SF.net SVN: r-gregmisc:[1600] trunk/gdata/man/read.xls.Rd
Brought to you by:
warnes
From: <wa...@us...> - 2012-08-22 16:42:54
|
Revision: 1600 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1600&view=rev Author: warnes Date: 2012-08-22 16:42:48 +0000 (Wed, 22 Aug 2012) Log Message: ----------- Add example for read.xls() that shows how to use the fileEncoding argument to read in latin-1 encoded data. Modified Paths: -------------- trunk/gdata/man/read.xls.Rd Modified: trunk/gdata/man/read.xls.Rd =================================================================== --- trunk/gdata/man/read.xls.Rd 2012-08-22 16:41:30 UTC (rev 1599) +++ trunk/gdata/man/read.xls.Rd 2012-08-22 16:42:48 UTC (rev 1600) @@ -87,64 +87,71 @@ \dontrun{ - # Example specifying exact Perl path for default MS-Windows install of - # ActiveState perl + ## Example specifying exact Perl path for default MS-Windows install of + ## ActiveState perl iris <- read.xls(xlsfile, perl="C:/perl/bin/perl.exe") } \dontrun{ - # Example specifying exact Perl path for Unix systems + ## Example specifying exact Perl path for Unix systems iris <- read.xls(xlsfile, perl="/usr/bin/perl") - # finding perl - # (read.xls automatically calls findPerl so this is rarely needed) + ## finding perl + ## (read.xls automatically calls findPerl so this is rarely needed) perl <- gdata:::findPerl("perl") iris <- read.xls(xlsfile, perl=perl) } \dontrun{ - # read xls file from net + ## read xls file from net nba.url <- "http://mgtclass.mgt.unm.edu/Bose/Excel/Tutorial.05/Cases/NBA.xls" nba <- read.xls(nba.url) } \dontrun{ - # read xls file ignoring all lines prior to first containing State + ## read xls file ignoring all lines prior to first containing State crime.url <- "http://www.jrsainfo.org/jabg/state_data2/Tribal_Data00.xls" crime <- read.xls(crime.url, pattern = "State") - # use of xls2csv - open con, print two lines, close con + ## use of xls2csv - open con, print two lines, close con con <- xls2csv(crime.url) print(readLines(con, 2)) file.remove(summary(con)$description) } - # Examples demonstrating selection of specific 'sheets' - # from the example XLS file 'ExampleExcelFile.xls' + ## Examples demonstrating selection of specific 'sheets' + ## from the example XLS file 'ExampleExcelFile.xls' exampleFile <- file.path(.path.package('gdata'),'xls', 'ExampleExcelFile.xls') exampleFile2007 <- file.path(.path.package('gdata'),'xls', 'ExampleExcelFile.xlsx') - # see the number and names of sheets: + ## see the number and names of sheets: sheetCount(exampleFile) - if( 'XLSX' \%in\% xlsFormats() ) # if XLSX is supported.. + if( 'XLSX' \%in\% xlsFormats() ) ## if XLSX is supported.. sheetCount(exampleFile2007) - # show names of shets in the file + ## show names of shets in the file sheetNames(exampleFile) - if( 'XLSX' \%in\% xlsFormats() ) # if XLSX is supported.. + if( 'XLSX' \%in\% xlsFormats() ) ## if XLSX is supported.. sheetNames(exampleFile2007) - data <- read.xls(exampleFile) # default is first worksheet - data <- read.xls(exampleFile, sheet=2) # second worksheet by number - data <- read.xls(exampleFile, sheet="Sheet Second",v=TRUE) # and by name + data <- read.xls(exampleFile) ## default is first worksheet + data <- read.xls(exampleFile, sheet=2) ## second worksheet by number + data <- read.xls(exampleFile, sheet="Sheet Second",v=TRUE) ## and by name - # load the third worksheet, skipping the first two non-data lines... - if( 'XLSX' \%in\% xlsFormats() ) # if XLSX is supported.. + ## load the third worksheet, skipping the first two non-data lines... + if( 'XLSX' \%in\% xlsFormats() ) ## if XLSX is supported.. data <- read.xls(exampleFile2007, sheet="Sheet with initial text", skip=2) + ## load a file containing data and column names using latin-1 + ## characters + latinFile <- file.path(.path.package('gdata'),'xls','latin-1.xls') + latin1 <- read.xls(latinFile, fileEncoding="latin1") + colnames(latin1) + + } \author{ Gregory R. Warnes \email{gr...@wa...}, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |