[R-gregmisc-users] SF.net SVN: r-gregmisc:[1541] trunk/gdata
Brought to you by:
warnes
From: <wa...@us...> - 2012-06-06 01:21:51
|
Revision: 1541 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1541&view=rev Author: warnes Date: 2012-06-06 01:21:44 +0000 (Wed, 06 Jun 2012) Log Message: ----------- Add na.strings to read.xls call to convert "#DIV/0!" to NA. Modified Paths: -------------- trunk/gdata/R/read.xls.R trunk/gdata/man/read.xls.Rd trunk/gdata/tests/test.read.xls.R Modified: trunk/gdata/R/read.xls.R =================================================================== --- trunk/gdata/R/read.xls.R 2012-06-05 20:09:50 UTC (rev 1540) +++ trunk/gdata/R/read.xls.R 2012-06-06 01:21:44 UTC (rev 1541) @@ -1,7 +1,9 @@ ## s$Id$ -read.xls <- function(xls, sheet = 1, verbose=FALSE, pattern, ..., - method=c("csv","tsv","tab"), perl="perl") +read.xls <- function(xls, sheet = 1, verbose=FALSE, pattern, + na.strings = c("NA","#DIV/0!"), ..., + method=c("csv","tsv","tab"), + perl="perl") { con <- tfn <- NULL on.exit({ @@ -36,9 +38,9 @@ cat("Reading", method, "file ", dQuote(tfn), "...\n") if(method=="csv") - retval <- read.csv(con, ...) + retval <- read.csv(con, na.strings=na.strings, ...) else if (method %in% c("tsv","tab") ) - retval <- read.delim(con, ...) + retval <- read.delim(con, na.strings=na.strings, ...) else stop("Unknown method", method) @@ -62,9 +64,9 @@ cat("Reading", method, "file ", dQuote(tfn), "...\n") if(method=="csv") - retval <- read.csv(con, skip = idx[1]-1, ...) + retval <- read.csv(con, skip = idx[1]-1, na.strings=na.strings, ...) else if (method %in% c("tsv","tab") ) - retval <- read.delim(con, skip = idx[1]-1, ...) + retval <- read.delim(con, skip = idx[1]-1, na.strings=na.strings, ...) else stop("Unknown method", method) Modified: trunk/gdata/man/read.xls.Rd =================================================================== --- trunk/gdata/man/read.xls.Rd 2012-06-05 20:09:50 UTC (rev 1540) +++ trunk/gdata/man/read.xls.Rd 2012-06-06 01:21:44 UTC (rev 1541) @@ -7,8 +7,8 @@ \title{Read Excel files} \description{Read a Microsoft Excel file into a data frame} \usage{ -read.xls(xls, sheet = 1, verbose=FALSE, pattern, ..., - method=c("csv","tsv","tab"), perl="perl") +read.xls(xls, sheet=1, verbose=FALSE, pattern, na.strings=c("NA","#DIV/0!"), + ..., method=c("csv","tsv","tab"), perl="perl") xls2csv(xls, sheet=1, verbose=FALSE, ..., perl="perl") xls2tab(xls, sheet=1, verbose=FALSE, ..., perl="perl") xls2tsv(xls, sheet=1, verbose=FALSE, ..., perl="perl") @@ -26,6 +26,8 @@ \item{perl}{name of the perl executable to be called.} \item{method}{intermediate file format, "csv" for comma-separated and "tab" for tab-separated} + \item{na.strings}{a character vector of strings which are to be interpreted + as ‘NA’ values. See \code{\link[utils]{read.table}} for details.} \item{...}{additional arguments to read.table. The defaults for read.csv() are used.} } Modified: trunk/gdata/tests/test.read.xls.R =================================================================== --- trunk/gdata/tests/test.read.xls.R 2012-06-05 20:09:50 UTC (rev 1540) +++ trunk/gdata/tests/test.read.xls.R 2012-06-06 01:21:44 UTC (rev 1541) @@ -43,10 +43,10 @@ example.2 <- read.xls(exampleFile, sheet=2) # second worksheet by number example.2 -example.3 <- read.xls(exampleFile, sheet=3) # second worksheet by number +example.3 <- read.xls(exampleFile, sheet=3, header=FALSE) # third worksheet by number example.3 -example.4 <- read.xls(exampleFile, sheet=3) # second worksheet by number +example.4 <- read.xls(exampleFile, sheet=3, header=FALSE) # third worksheet by number example.4 if( 'XLSX' %in% xlsFormats() ) @@ -57,10 +57,10 @@ example.x.2 <- read.xls(exampleFile2007, sheet=2) # second worksheet by number print(example.x.2) - example.x.3 <- read.xls(exampleFile2007, sheet=3) # second worksheet by number + example.x.3 <- read.xls(exampleFile2007, sheet=3, header=FALSE) # third worksheet by number print(example.x.3) - example.x.4 <- read.xls(exampleFile2007, sheet=3) # second worksheet by number + example.x.4 <- read.xls(exampleFile2007, sheet=3, header=FALSE) # third worksheet by number print(example.x.4) data <- read.xls(exampleFile2007, sheet="Sheet Second") # and by name This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |