[R-gregmisc-users] SF.net SVN: r-gregmisc:[1383] trunk/gdata/R
Brought to you by:
warnes
From: <wa...@us...> - 2010-01-23 05:50:16
|
Revision: 1383 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1383&view=rev Author: warnes Date: 2010-01-23 05:50:10 +0000 (Sat, 23 Jan 2010) Log Message: ----------- Update to match new xls2csv.pl code, allow specification of sheets by name, support CSV and TAB delimited files using the same code, other minor changes. Modified Paths: -------------- trunk/gdata/R/read.xls.R trunk/gdata/R/xls2sep.R Modified: trunk/gdata/R/read.xls.R =================================================================== --- trunk/gdata/R/read.xls.R 2010-01-23 05:45:13 UTC (rev 1382) +++ trunk/gdata/R/read.xls.R 2010-01-23 05:50:10 UTC (rev 1383) @@ -1,7 +1,7 @@ ## s$Id$ read.xls <- function(xls, sheet = 1, verbose=FALSE, pattern, ..., - method=c("csv","tab"), perl="perl") + method=c("csv","tsv","tab"), perl="perl") { con <- tfn <- NULL on.exit({ @@ -15,13 +15,8 @@ xls <- path.expand(xls) - ## translate from xls to csv/tab format (returns csv file name) - if(method=="csv") - con <- xls2csv(xls, sheet, verbose=verbose, ..., perl = perl) - else if(method=="tab") - con <- xls2tab(xls, sheet, verbose=verbose, ..., perl = perl) - else - stop("Unknown method", method) + ## translate from xls to csv/tsv/tab format (returns name of created file) + con <- xls2sep(xls, sheet, verbose=verbose, ..., method=method, perl = perl) ## load the csv file open(con) @@ -35,7 +30,7 @@ if(method=="csv") retval <- read.csv(con, ...) - else if (method=="tab") + else if (method %in% c("tsv","tab") ) retval <- read.delim(con, ...) else stop("Unknown method", method) @@ -60,7 +55,7 @@ if(method=="csv") retval <- read.csv(con, skip = idx[1]-1, ...) - else if (method=="tab") + else if (method %in% c("tsv","tab") ) retval <- read.delim(con, skip = idx[1]-1, ...) else stop("Unknown method", method) Modified: trunk/gdata/R/xls2sep.R =================================================================== --- trunk/gdata/R/xls2sep.R 2010-01-23 05:45:13 UTC (rev 1382) +++ trunk/gdata/R/xls2sep.R 2010-01-23 05:50:10 UTC (rev 1383) @@ -9,7 +9,7 @@ perl=perl) xls2sep <- function(xls, sheet = 1, verbose=FALSE, ..., - method=c("csv","tab"), perl="perl") + method=c("csv","tsv","tab"), perl="perl") { method <- match.arg(method) @@ -51,6 +51,11 @@ script <- file.path(perl.dir,'xls2tab.pl') targetFile <- paste(tempfile(), "tab", sep = ".") } + else if(method=="tsv") + { + script <- file.path(perl.dir,'xls2tsv.pl') + targetFile <- paste(tempfile(), "tsv", sep = ".") + } else { stop("Unknown method", method) @@ -89,7 +94,7 @@ ## if(file.access(targetFile, 4)!=0) - stop("Unable to read translated", method, "file '", targetFile, "'." ) + stop("Unable to read translated ", method, " file '", targetFile, "'." ) cat("Done.\n") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |