[R-gregmisc-users] SF.net SVN: r-gregmisc:[1435] trunk/gdata
Brought to you by:
warnes
|
From: <wa...@us...> - 2010-05-02 06:11:33
|
Revision: 1435
http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1435&view=rev
Author: warnes
Date: 2010-05-02 06:11:26 +0000 (Sun, 02 May 2010)
Log Message:
-----------
Update perl code to work (but generate warnings) when Zlib or SpreadSheet::XLXS is not instaled. Also update Greg's email address
Modified Paths:
--------------
trunk/gdata/DESCRIPTION
trunk/gdata/NAMESPACE
trunk/gdata/R/dQuote.ascii.R
trunk/gdata/R/read.xls.R
trunk/gdata/inst/doc/gregmisc.tex
trunk/gdata/inst/perl/sheetCount.pl
trunk/gdata/inst/perl/xls2csv.pl
trunk/gdata/man/ConvertMedUnits.Rd
trunk/gdata/man/aggregate.table.Rd
trunk/gdata/man/combine.Rd
trunk/gdata/man/interleave.Rd
trunk/gdata/man/matchcols.Rd
trunk/gdata/man/nobs.Rd
trunk/gdata/man/read.xls.Rd
trunk/gdata/man/rename.vars.Rd
trunk/gdata/man/reorder.Rd
trunk/gdata/man/resample.Rd
trunk/gdata/man/sheetCount.Rd
trunk/gdata/man/trim.Rd
trunk/gdata/man/unmatrix.Rd
trunk/gdata/man/upperTriangle.Rd
trunk/gdata/tests/test.read.xls.R
trunk/gdata/tests/test.read.xls.Rout.save
trunk/gdata/tests/tests.write.fwf.Rout.save
Added Paths:
-----------
trunk/gdata/R/findPerl.R
trunk/gdata/R/xlsFormats.R
trunk/gdata/inst/perl/install_modules.pl
trunk/gdata/inst/perl/module_tools.pl
trunk/gdata/inst/perl/supportedFormats.pl
trunk/gdata/man/xlsFormats.Rd
Removed Paths:
-------------
trunk/gdata/src/
Modified: trunk/gdata/DESCRIPTION
===================================================================
--- trunk/gdata/DESCRIPTION 2010-05-01 22:14:05 UTC (rev 1434)
+++ trunk/gdata/DESCRIPTION 2010-05-02 06:11:26 UTC (rev 1435)
@@ -3,10 +3,10 @@
Description: Various R programming tools for data manipulation
Depends: R (>= 2.6.0)
Imports: gtools
-Version: 2.7.1
-Date: 2010-01-27
+Version: 2.7.2
+Date: 2010-04-02
Author: Gregory R. Warnes, with contributions from Ben Bolker, Gregor Gorjanc,
Gabor Grothendieck, Ales Korosec, Thomas Lumley, Don MacQueen,
Arni Magnusson, Jim Rogers, and others
-Maintainer: Gregory Warnes <gr...@ra...>
+Maintainer: Gregory Warnes <gr...@wa...>
License: GPL-2
Modified: trunk/gdata/NAMESPACE
===================================================================
--- trunk/gdata/NAMESPACE 2010-05-01 22:14:05 UTC (rev 1434)
+++ trunk/gdata/NAMESPACE 2010-05-02 06:11:26 UTC (rev 1435)
@@ -36,7 +36,8 @@
xls2csv,
xls2tab,
xls2tsv,
- xls2sep,
+ xls2sep,
+ xlsFormats,
## Object size stuff
object.size, as.object_size, is.object_size, humanReadable,
Modified: trunk/gdata/R/dQuote.ascii.R
===================================================================
--- trunk/gdata/R/dQuote.ascii.R 2010-05-01 22:14:05 UTC (rev 1434)
+++ trunk/gdata/R/dQuote.ascii.R 2010-05-02 06:11:26 UTC (rev 1435)
@@ -7,25 +7,3 @@
##
dQuote.ascii <- function(x) paste('"',x,'"',sep='')
-findPerl <- function(perl, verbose = "FALSE") {
-
- if (missing(perl)) {
- if (.Platform$OS == "windows") {
- perl <- Sys.which("perl")
- if (perl == "") stop("perl not found. Use perl= argument.")
- if (length(grep("rtools", tolower(perl))) > 0) {
- perl.ftype <- shell("ftype perl", intern = TRUE)
- if (length(grep("^perl=", perl.ftype)) > 0) {
- perl <- sub('^perl="([^"]*)".*', "\\1", perl.ftype)
- }
- }
- }
- if (perl == "perl") perl <- Sys.which("perl")
- }
-
- if (verbose) cat("Using perl at", perl, "\n")
-
- perl
-}
-
-
Added: trunk/gdata/R/findPerl.R
===================================================================
--- trunk/gdata/R/findPerl.R (rev 0)
+++ trunk/gdata/R/findPerl.R 2010-05-02 06:11:26 UTC (rev 1435)
@@ -0,0 +1,34 @@
+## s$Id: read.xls.R 1342 2009-07-16 02:49:11Z warnes $
+
+## findPerl attempts to locate a valid perl executable. If the 'perl' argument is missing,
+
+
+findPerl <- function(perl, verbose = "FALSE")
+{
+
+ errorMsg <- "perl executable not found. Use perl= argument to specify the correct path."
+
+ if (missing(perl))
+ {
+ perl = "perl"
+ }
+
+ perl = Sys.which(perl)
+ if (perl=="" || perl=="perl")
+ stop(errorMsg)
+
+ if (.Platform$OS == "windows") {
+ if (length(grep("rtools", tolower(perl))) > 0) {
+ perl.ftype <- shell("ftype perl", intern = TRUE)
+ if (length(grep("^perl=", perl.ftype)) > 0) {
+ perl <- sub('^perl="([^"]*)".*', "\\1", perl.ftype)
+ }
+ }
+ }
+
+ if (verbose) cat("Using perl at", perl, "\n")
+
+ perl
+}
+
+
Modified: trunk/gdata/R/read.xls.R
===================================================================
--- trunk/gdata/R/read.xls.R 2010-05-01 22:14:05 UTC (rev 1434)
+++ trunk/gdata/R/read.xls.R 2010-05-02 06:11:26 UTC (rev 1435)
@@ -20,8 +20,11 @@
## translate from xls to csv/tsv/tab format (returns name of created file)
- perl <- if (missing(perl)) findPerl(verbose = verbose)
- else findPerl(perl, verbose = verbose)
+ perl <- if (missing(perl))
+ findPerl(verbose = verbose)
+ else
+ findPerl(perl, verbose = verbose)
+
con <- xls2sep(xls, sheet, verbose=verbose, ..., method=method, perl = perl)
## load the csv file
Added: trunk/gdata/R/xlsFormats.R
===================================================================
--- trunk/gdata/R/xlsFormats.R (rev 0)
+++ trunk/gdata/R/xlsFormats.R 2010-05-02 06:11:26 UTC (rev 1435)
@@ -0,0 +1,52 @@
+## s$Id: read.xls.R 1423 2010-02-21 17:12:30Z ggrothendieck2 $
+
+xlsFormats <- function(perl="perl", verbose=FALSE)
+{
+ ## determine proper path to perl executable
+ perl <- if (missing(perl))
+ findPerl(verbose = verbose)
+ else
+ findPerl(perl, verbose = verbose)
+
+ ##
+ ## directories
+ package.dir <- .path.package('gdata')
+ perl.dir <- file.path(package.dir,'perl')
+ ##
+ ##
+
+ cmd <- "supportedFormats.pl"
+ sc <- file.path(perl.dir, cmd)
+
+ ##
+ ##
+
+ ##
+ ## execution command
+
+ cmd <- paste(perl, sc, sep=" ")
+
+ ##
+
+ if(verbose)
+ {
+ cat("\n")
+ cat("Determining supported formats...\n")
+ cat("\n")
+ }
+
+ ##
+
+ output <- system(cmd, intern=TRUE)
+
+ ##
+
+ if(verbose) cat("Results: ", output, "\n")
+
+ ##
+
+ retval <- unlist( strsplit(output," "))
+ retval <- retval[ -c(1,2) ]
+
+ return(retval)
+}
Modified: trunk/gdata/inst/doc/gregmisc.tex
===================================================================
--- trunk/gdata/inst/doc/gregmisc.tex 2010-05-01 22:14:05 UTC (rev 1434)
+++ trunk/gdata/inst/doc/gregmisc.tex 2010-05-02 06:11:26 UTC (rev 1435)
@@ -96,7 +96,7 @@
\address{Gregory R. Warnes \\
Random Technologies LLC. \\
- \emph{gr...@ra...} } %%!!!%%
+ \emph{gr...@wa...} } %%!!!%%
\end{multicols} %%!!!%%
Added: trunk/gdata/inst/perl/install_modules.pl
===================================================================
--- trunk/gdata/inst/perl/install_modules.pl (rev 0)
+++ trunk/gdata/inst/perl/install_modules.pl 2010-05-02 06:11:26 UTC (rev 1435)
@@ -0,0 +1,12 @@
+
+require 'module_tools.pl';
+
+my( $HAS_Spreadsheet_ParseExcel, $HAS_Compress_Raw_Zlib, $HAS_Spreadsheet_XLSX);
+
+# check if we need to do anything
+
+($HAS_Spreadsheet_ParseExcel,
+ $HAS_Compress_Raw_Zlib,
+ $HAS_Spreadsheet_XLSX) = check_modules(0);
+
+install_modules() unless $HAS_Compress_Raw_Zlib;
Added: trunk/gdata/inst/perl/module_tools.pl
===================================================================
--- trunk/gdata/inst/perl/module_tools.pl (rev 0)
+++ trunk/gdata/inst/perl/module_tools.pl 2010-05-02 06:11:26 UTC (rev 1435)
@@ -0,0 +1,108 @@
+#!/usr/bin/perl
+
+BEGIN {
+ use File::Basename;
+ # Add current path to perl library search path
+ use lib dirname($0);
+}
+
+use strict;
+use warnings;
+use Data::Dumper;
+use Cwd;
+
+sub check_modules(;$)
+ {
+ my(
+ $VERBOSE,
+ $HAS_Spreadsheet_ParseExcel,
+ $HAS_Compress_Raw_Zlib,
+ $HAS_Spreadsheet_XLSX
+ );
+ $VERBOSE=$_[0];
+
+ # Check if we can load the libraries we need
+ eval
+ {
+ require Spreadsheet::ParseExcel;
+ $HAS_Spreadsheet_ParseExcel=1;
+ print "Loaded Spreadsheet::ParseExcel\n" if $VERBOSE;
+
+ };
+ eval
+ {
+ require Compress::Raw::Zlib;
+ $HAS_Compress_Raw_Zlib=1;
+ print "Loaded Compress::Raw::Zlib\n" if $VERBOSE;
+ };
+ eval
+ {
+ require Spreadsheet::XLSX;
+ $HAS_Spreadsheet_XLSX=1;
+ print "Loaded Spreadsheet::XLSX\n" if $VERBOSE;
+ };
+
+ if($VERBOSE)
+ {
+ print "ERROR: Unable to load Spreadsheet::ParseExcel perl module! \n"
+ if !$HAS_Spreadsheet_ParseExcel;
+ print "ERROR: Unable to load Compress::Raw::Zlib perl module! \n"
+ if ! $HAS_Compress_Raw_Zlib;
+ print "ERROR: Unable to load Spreadsheet::XLSX perl module! \n"
+ if ! $HAS_Spreadsheet_XLSX;
+ }
+
+ return $HAS_Spreadsheet_ParseExcel, $HAS_Compress_Raw_Zlib, $HAS_Spreadsheet_XLSX;
+ }
+
+sub check_modules_and_notify()
+ {
+ my(
+ $HAS_Spreadsheet_ParseExcel,
+ $HAS_Compress_Raw_Zlib,
+ $HAS_Spreadsheet_XLSX) = check_modules(0);
+
+ $HAS_Spreadsheet_ParseExcel or
+ die("ERROR: Perl module Spreadsheet::ParseExcel cannot be loaded. Exiting.\n");
+
+ $HAS_Compress_Raw_Zlib or
+ warn("WARNING: Perl module Compress::Raw::Zlib cannot be loaded.\n");
+
+ $HAS_Spreadsheet_XLSX or
+ warn("WARNING: Perl module Spreadsheet::XLSX cannot be loaded.\n");
+
+ ($HAS_Compress_Raw_Zlib && $HAS_Spreadsheet_XLSX ) or
+ warn("WARNING: Microsoft Excel 2007 'XLSX' formatted files will not be processed.\n");
+ return $HAS_Spreadsheet_ParseExcel, $HAS_Compress_Raw_Zlib, $HAS_Spreadsheet_XLSX;
+ }
+
+sub install_modules()
+ {
+ my($mod, $obj, $here);
+
+ $here = getcwd();
+
+ # load the module
+ require CPAN;
+
+ # initialize CPAN components
+ CPAN::HandleConfig->load();
+ CPAN::Shell::setup_output();
+ CPAN::Index->reload();
+
+ # set the target install path
+ CPAN::Shell->o("conf", "makepl_arg",
+ "PREFIX=$here LIB=$here --prefix $here --install-base $here");
+ CPAN::Shell->install("Compress::Raw::Zlib");
+
+ #return 0;
+
+ # install the libraries we want
+ for $mod (qw( Compress::Raw::Zlib Spreadsheet::XLSX )){
+ my $obj = CPAN::Shell->expand('Module',$mod);
+ $obj->install;
+ }
+
+ }
+
+1;
Property changes on: trunk/gdata/inst/perl/module_tools.pl
___________________________________________________________________
Added: svn:executable
+ *
Modified: trunk/gdata/inst/perl/sheetCount.pl
===================================================================
--- trunk/gdata/inst/perl/sheetCount.pl 2010-05-01 22:14:05 UTC (rev 1434)
+++ trunk/gdata/inst/perl/sheetCount.pl 2010-05-02 06:11:26 UTC (rev 1435)
@@ -7,8 +7,17 @@
}
use strict;
-use Spreadsheet::ParseExcel;
-use Spreadsheet::XLSX;
+##
+# Try to load the modules we need
+##
+require 'module_tools.pl';
+
+my(
+ $HAS_Spreadsheet_ParseExcel,
+ $HAS_Compress_Raw_Zlib,
+ $HAS_Spreadsheet_XLSX
+ ) = check_modules_and_notify();
+
use File::Spec::Functions;
# declare some varibles local
Added: trunk/gdata/inst/perl/supportedFormats.pl
===================================================================
--- trunk/gdata/inst/perl/supportedFormats.pl (rev 0)
+++ trunk/gdata/inst/perl/supportedFormats.pl 2010-05-02 06:11:26 UTC (rev 1435)
@@ -0,0 +1,26 @@
+#!/usr/bin/perl
+
+BEGIN {
+ use File::Basename;
+ # Add current path to perl library search path
+ use lib dirname($0);
+}
+
+require 'module_tools.pl';
+
+my( $HAS_Spreadsheet_ParseExcel,
+ $HAS_Compress_Raw_Zlib,
+ $HAS_Spreadsheet_XLSX) = check_modules(0);
+
+$XLS_Support = $HAS_Spreadsheet_ParseExcel;
+$XLSX_Support = $HAS_Spreadsheet_ParseExcel &&
+ $HAS_Compress_Raw_Zlib &&
+ $HAS_Spreadsheet_XLSX;
+
+printf "Supported formats: ";
+printf "XLS " if ( $XLS_Support );
+printf "XLSX" if ( $XLSX_Support );
+printf "\n";
+
+
+
Modified: trunk/gdata/inst/perl/xls2csv.pl
===================================================================
--- trunk/gdata/inst/perl/xls2csv.pl 2010-05-01 22:14:05 UTC (rev 1434)
+++ trunk/gdata/inst/perl/xls2csv.pl 2010-05-02 06:11:26 UTC (rev 1435)
@@ -7,13 +7,22 @@
}
use strict;
-use Spreadsheet::ParseExcel;
-use Spreadsheet::XLSX;
+#use Spreadsheet::ParseExcel;
+#use Spreadsheet::XLSX;
use POSIX;
use File::Spec::Functions;
+##
+# Try to load the modules we need
+##
+require 'module_tools.pl';
+my(
+ $HAS_Spreadsheet_ParseExcel,
+ $HAS_Compress_Raw_Zlib,
+ $HAS_Spreadsheet_XLSX
+ ) = check_modules_and_notify();
+
# declare some varibles local
-
my($row, $col, $sheet, $cell, $usage,
$targetfile,$basename, $sheetnumber,
$filename, $volume, $directories, $whoami,
Modified: trunk/gdata/man/ConvertMedUnits.Rd
===================================================================
--- trunk/gdata/man/ConvertMedUnits.Rd 2010-05-01 22:14:05 UTC (rev 1434)
+++ trunk/gdata/man/ConvertMedUnits.Rd 2010-05-02 06:11:26 UTC (rev 1435)
@@ -46,7 +46,7 @@
\references{
\url{http://www.globalrph.com/conv_si.htm}
}
-\author{ Gregory R. Warnes \email{gr...@ra...} }
+\author{ Gregory R. Warnes \email{gr...@wa...} }
\examples{
data(MedUnits)
Modified: trunk/gdata/man/aggregate.table.Rd
===================================================================
--- trunk/gdata/man/aggregate.table.Rd 2010-05-01 22:14:05 UTC (rev 1434)
+++ trunk/gdata/man/aggregate.table.Rd 2010-05-02 06:11:26 UTC (rev 1435)
@@ -49,7 +49,7 @@
Returns a matrix with one element for each combination of \code{by1}
and \code{by2}.
}
-\author{ Gregory R. Warnes \email{gr...@ra...}}
+\author{ Gregory R. Warnes \email{gr...@wa...}}
\seealso{ \code{\link{aggregate}}, \code{\link{tapply}},
\code{\link{interleave}} }
Modified: trunk/gdata/man/combine.Rd
===================================================================
--- trunk/gdata/man/combine.Rd 2010-05-01 22:14:05 UTC (rev 1434)
+++ trunk/gdata/man/combine.Rd 2010-05-02 06:11:26 UTC (rev 1435)
@@ -59,7 +59,7 @@
% ...
% }
%\references{ ~put references to the literature/web site here ~ }
-\author{Gregory R. Warnes \email{gr...@ra...}}
+\author{Gregory R. Warnes \email{gr...@wa...}}
%\note{ ~~further notes~~ }
\seealso{ \code{\link{rbind}}, \code{\link{merge}}}
Modified: trunk/gdata/man/interleave.Rd
===================================================================
--- trunk/gdata/man/interleave.Rd 2010-05-01 22:14:05 UTC (rev 1434)
+++ trunk/gdata/man/interleave.Rd 2010-05-02 06:11:26 UTC (rev 1435)
@@ -66,7 +66,7 @@
\value{
Matrix containing the interleaved rows of the function arguments.
}
-\author{ Gregory R. Warnes \email{gr...@ra...}
+\author{ Gregory R. Warnes \email{gr...@wa...}
}
\seealso{ \code{\link{cbind}}, \code{\link{rbind}}, \code{\link{combine}} }
Modified: trunk/gdata/man/matchcols.Rd
===================================================================
--- trunk/gdata/man/matchcols.Rd 2010-05-01 22:14:05 UTC (rev 1434)
+++ trunk/gdata/man/matchcols.Rd 2010-05-02 06:11:26 UTC (rev 1435)
@@ -20,7 +20,7 @@
none of the patterns specified in \code{without}.
}
-\author{Gregory R. Warnes \email{gr...@ra...}}
+\author{Gregory R. Warnes \email{gr...@wa...}}
\seealso{ \code{\link[base]{grep}} }
\examples{
Modified: trunk/gdata/man/nobs.Rd
===================================================================
--- trunk/gdata/man/nobs.Rd 2010-05-01 22:14:05 UTC (rev 1434)
+++ trunk/gdata/man/nobs.Rd 2010-05-02 06:11:26 UTC (rev 1435)
@@ -58,7 +58,7 @@
A single numeric value or a vector of values (for data.frames) giving
the number of non-missing values.
}
-\author{ Gregory R. Warnes \email{gr...@ra...} }
+\author{ Gregory R. Warnes \email{gr...@wa...} }
\seealso{ \code{\link{is.na}}, \code{\link{length}} }
Modified: trunk/gdata/man/read.xls.Rd
===================================================================
--- trunk/gdata/man/read.xls.Rd 2010-05-01 22:14:05 UTC (rev 1434)
+++ trunk/gdata/man/read.xls.Rd 2010-05-02 06:11:26 UTC (rev 1435)
@@ -109,18 +109,21 @@
# see the number and names of sheets:
sheetCount(exampleFile)
- sheetNames(exampleFile2007)
+ 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
# load the third worksheet, skipping the first two non-data lines...
- data <- read.xls(exampleFile2007, sheet="Sheet with initial text", skip=2)
+ if( 'XLSX' \%in\% xlsFormats() ) # if XLSX is supported..
+ data <- read.xls(exampleFile2007, sheet="Sheet with initial text", skip=2)
}
\author{
- Gregory R. Warnes \email{gr...@ra...},
+ Gregory R. Warnes \email{gr...@wa...},
Jim Rogers \email{jam...@pf...}, and
Gabor Grothendiek \email{ggr...@gm...}.
}
Modified: trunk/gdata/man/rename.vars.Rd
===================================================================
--- trunk/gdata/man/rename.vars.Rd 2010-05-01 22:14:05 UTC (rev 1434)
+++ trunk/gdata/man/rename.vars.Rd 2010-05-02 06:11:26 UTC (rev 1435)
@@ -49,7 +49,7 @@
}
\author{Code by Don MacQueen \email{macq\@llnl.gov}.
Documentation by Gregory R. Warnes
- \email{gr...@ra...} }
+ \email{gr...@wa...} }
\seealso{ \code{\link{names}},
\code{\link{colnames}},
\code{\link{data.frame}}
Modified: trunk/gdata/man/reorder.Rd
===================================================================
--- trunk/gdata/man/reorder.Rd 2010-05-01 22:14:05 UTC (rev 1434)
+++ trunk/gdata/man/reorder.Rd 2010-05-02 06:11:26 UTC (rev 1435)
@@ -56,7 +56,7 @@
A new factor with reordered levels
}
-\author{Gregory R. Warnes \email{gr...@ra...}}
+\author{Gregory R. Warnes \email{gr...@wa...}}
\seealso{\code{\link{factor}} and \code{\link[stats]{reorder}}}
Modified: trunk/gdata/man/resample.Rd
===================================================================
--- trunk/gdata/man/resample.Rd 2010-05-01 22:14:05 UTC (rev 1434)
+++ trunk/gdata/man/resample.Rd 2010-05-02 06:11:26 UTC (rev 1435)
@@ -27,7 +27,7 @@
\value{
Vector of the same length as the input, with the elements permuted.
}
-\author{Gregory R. Warnes \email{gr...@ra...} }
+\author{Gregory R. Warnes \email{gr...@wa...} }
\seealso{ \code{\link{sample}} }
\examples{
Modified: trunk/gdata/man/sheetCount.Rd
===================================================================
--- trunk/gdata/man/sheetCount.Rd 2010-05-01 22:14:05 UTC (rev 1434)
+++ trunk/gdata/man/sheetCount.Rd 2010-05-02 06:11:26 UTC (rev 1435)
@@ -40,8 +40,10 @@
'ExampleExcelFile.xlsx')
sheetCount(exampleFile)
- sheetNames(exampleFile2007)
+ if( 'XLSX' \%in\% xlsFormats() ) # if XLSX is supported..
+ sheetNames(exampleFile2007)
+
}
\keyword{ misc }
Modified: trunk/gdata/man/trim.Rd
===================================================================
--- trunk/gdata/man/trim.Rd 2010-05-01 22:14:05 UTC (rev 1434)
+++ trunk/gdata/man/trim.Rd 2010-05-02 06:11:26 UTC (rev 1435)
@@ -32,7 +32,7 @@
\value{
\code{s} with all leading and trailing spaces removed in its elements.
}
-\author{Gregory R. Warnes \email{gr...@ra...} with
+\author{Gregory R. Warnes \email{gr...@wa...} with
contributions by Gregor Gorjanc}
\seealso{ \code{\link[base]{sub}}, \code{\link[base]{gsub}} as well as
argument \code{strip.white} in \code{\link{read.table}} and
Modified: trunk/gdata/man/unmatrix.Rd
===================================================================
--- trunk/gdata/man/unmatrix.Rd 2010-05-01 22:14:05 UTC (rev 1434)
+++ trunk/gdata/man/unmatrix.Rd 2010-05-02 06:11:26 UTC (rev 1435)
@@ -19,7 +19,7 @@
matrix. If the the row or column names are missing, ('r1', 'r2', ..,) or
('c1', 'c2', ..) will be used as appropriate.
}
-\author{Gregory R. Warnes \email{gr...@ra...} }
+\author{Gregory R. Warnes \email{gr...@wa...} }
\seealso{ \code{\link[base]{as.vector}} }
\examples{
# simple, useless example
Modified: trunk/gdata/man/upperTriangle.Rd
===================================================================
--- trunk/gdata/man/upperTriangle.Rd 2010-05-01 22:14:05 UTC (rev 1434)
+++ trunk/gdata/man/upperTriangle.Rd 2010-05-02 06:11:26 UTC (rev 1435)
@@ -28,7 +28,7 @@
replace the upper or lower traingular area of the
matrix with the provided value(s).
}
-\author{Gregory R. Warnes \email{gr...@ra...}}
+\author{Gregory R. Warnes \email{gr...@wa...}}
\seealso{ \code{\link[base]{diag}} }
\examples{
x <- matrix( 1:25, nrow=5, ncol=5)
Added: trunk/gdata/man/xlsFormats.Rd
===================================================================
--- trunk/gdata/man/xlsFormats.Rd (rev 0)
+++ trunk/gdata/man/xlsFormats.Rd 2010-05-02 06:11:26 UTC (rev 1435)
@@ -0,0 +1,33 @@
+\name{xlsFormats}
+\Rdversion{1.1}
+\alias{xlsFormats}
+\title{
+Determine which XLS file formats are supported by read.xls
+}
+\description{
+Determine which XLS file formats are supported by read.xls
+}
+\usage{
+xlsFormats(perl = "perl", verbose = FALSE)
+}
+\arguments{
+ \item{perl}{Path to perl interpreter (optional).}
+ \item{verbose}{If \code{TRUE}, show additional messages during
+ processing.}
+}
+\value{
+ Vector of supported formats, possible elements are 'XLS' and 'XLSX'.
+}
+
+\seealso{
+ \code{\link{read.xls}}, \code{\link{xls2csv}}.
+}
+\examples{
+ ## List supported formats
+ xlsFormats()
+
+ ## Example use
+ if( 'XLSX' \%in\% xlsFormats() ) # if XLSX is supported..
+ sheetNames(exampleFile2007)
+}
+\keyword{ misc }
Modified: trunk/gdata/tests/test.read.xls.R
===================================================================
--- trunk/gdata/tests/test.read.xls.R 2010-05-01 22:14:05 UTC (rev 1434)
+++ trunk/gdata/tests/test.read.xls.R 2010-05-02 06:11:26 UTC (rev 1435)
@@ -24,11 +24,15 @@
# see the number and names of sheets:
sheetCount(exampleFile)
-sheetCount(exampleFile2007)
+if( 'XLSX' %in% xlsFormats() )
+ sheetCount(exampleFile2007)
+
sheetNames(exampleFile)
-sheetNames(exampleFile2007)
+if( 'XLSX' %in% xlsFormats() )
+ sheetNames(exampleFile2007)
+
example.1 <- read.xls(exampleFile, sheet=1) # default is first worksheet
example.1
@@ -41,21 +45,24 @@
example.4 <- read.xls(exampleFile, sheet=3) # second worksheet by number
example.4
-example.x.1 <- read.xls(exampleFile2007, sheet=1) # default is first worksheet
-example.x.1
+if( 'XLSX' %in% xlsFormats() )
+ {
+ example.x.1 <- read.xls(exampleFile2007, sheet=1) # default is first worksheet
+ print(example.x.1)
-example.x.2 <- read.xls(exampleFile2007, sheet=2) # second worksheet by number
-example.x.2
+ 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
+ example.x.3 <- read.xls(exampleFile2007, sheet=3) # second worksheet by number
+ print(example.x.3)
-example.x.4 <- read.xls(exampleFile2007, sheet=3) # second worksheet by number
-example.x.4
+ example.x.4 <- read.xls(exampleFile2007, sheet=3) # second worksheet by number
+ print(example.x.4)
-data <- read.xls(exampleFile2007, sheet="Sheet Second") # and by name
-data
-
-# load the third worksheet, skipping the first two non-data lines...
-data <- read.xls(exampleFile2007, sheet="Sheet with initial text", skip=2)
-data
+ data <- read.xls(exampleFile2007, sheet="Sheet Second") # and by name
+ print(data)
+
+ # load the third worksheet, skipping the first two non-data lines...
+ data <- read.xls(exampleFile2007, sheet="Sheet with initial text", skip=2)
+ print(data)
+}
Modified: trunk/gdata/tests/test.read.xls.Rout.save
===================================================================
--- trunk/gdata/tests/test.read.xls.Rout.save 2010-05-01 22:14:05 UTC (rev 1434)
+++ trunk/gdata/tests/test.read.xls.Rout.save 2010-05-02 06:11:26 UTC (rev 1435)
@@ -1,6 +1,6 @@
-R version 2.10.1 (2009-12-14)
-Copyright (C) 2009 The R Foundation for Statistical Computing
+R version 2.11.0 (2010-04-22)
+Copyright (C) 2010 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
R is free software and comes with ABSOLUTELY NO WARRANTY.
@@ -21,17 +21,19 @@
Attaching package: 'gdata'
+The following object(s) are masked from 'package:utils':
- The following object(s) are masked from package:utils :
+ object.size
- object.size
-
>
>
> # iris.xls is included in the gregmisc package for use as an example
> xlsfile <- file.path(.path.package('gdata'),'xls','iris.xls')
>
> iris.1 <- read.xls(xlsfile) # defaults to csv format
+WARNING: Perl module Compress::Raw::Zlib cannot be loaded.
+WARNING: Perl module Spreadsheet::XLSX cannot be loaded.
+WARNING: Microsoft Excel 2007 'XLSX' formatted files will not be processed.
> iris.1
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 5.1 3.5 1.4 0.2 setosa
@@ -186,6 +188,9 @@
150 5.9 3.0 5.1 1.8 virginica
>
> iris.2 <- read.xls(xlsfile,method="csv") # specify csv format
+WARNING: Perl module Compress::Raw::Zlib cannot be loaded.
+WARNING: Perl module Spreadsheet::XLSX cannot be loaded.
+WARNING: Microsoft Excel 2007 'XLSX' formatted files will not be processed.
> iris.2
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 5.1 3.5 1.4 0.2 setosa
@@ -340,6 +345,9 @@
150 5.9 3.0 5.1 1.8 virginica
>
> iris.3 <- read.xls(xlsfile,method="tab") # specify tab format
+WARNING: Perl module Compress::Raw::Zlib cannot be loaded.
+WARNING: Perl module Spreadsheet::XLSX cannot be loaded.
+WARNING: Microsoft Excel 2007 'XLSX' formatted files will not be processed.
> iris.3
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 5.1 3.5 1.4 0.2 setosa
@@ -504,18 +512,28 @@
>
> # see the number and names of sheets:
> sheetCount(exampleFile)
+WARNING: Perl module Compress::Raw::Zlib cannot be loaded.
+WARNING: Perl module Spreadsheet::XLSX cannot be loaded.
+WARNING: Microsoft Excel 2007 'XLSX' formatted files will not be processed.
[1] 4
-> sheetCount(exampleFile2007)
-[1] 4
>
+> if( 'XLSX' %in% xlsFormats() )
++ sheetCount(exampleFile2007)
+>
> sheetNames(exampleFile)
+WARNING: Perl module Compress::Raw::Zlib cannot be loaded.
+WARNING: Perl module Spreadsheet::XLSX cannot be loaded.
+WARNING: Microsoft Excel 2007 'XLSX' formatted files will not be processed.
[1] "Sheet First" "Sheet Second"
[3] "Sheet with a very long name!" "Sheet with initial text"
-> sheetNames(exampleFile2007)
-[1] "Sheet First" "Sheet Second"
-[3] "Sheet with a very long name!" "Sheet with initial text"
>
+> if( 'XLSX' %in% xlsFormats() )
++ sheetNames(exampleFile2007)
+>
> example.1 <- read.xls(exampleFile, sheet=1) # default is first worksheet
+WARNING: Perl module Compress::Raw::Zlib cannot be loaded.
+WARNING: Perl module Spreadsheet::XLSX cannot be loaded.
+WARNING: Microsoft Excel 2007 'XLSX' formatted files will not be processed.
> example.1
A B C
1 1 1 1
@@ -527,6 +545,9 @@
7 7 49 343
>
> example.2 <- read.xls(exampleFile, sheet=2) # second worksheet by number
+WARNING: Perl module Compress::Raw::Zlib cannot be loaded.
+WARNING: Perl module Spreadsheet::XLSX cannot be loaded.
+WARNING: Microsoft Excel 2007 'XLSX' formatted files will not be processed.
> example.2
X D E F G Factor
1 FirstRow 1 NA NA NA Red
@@ -535,6 +556,9 @@
4 FourthRow 4 3 2 1 Black
>
> example.3 <- read.xls(exampleFile, sheet=3) # second worksheet by number
+WARNING: Perl module Compress::Raw::Zlib cannot be loaded.
+WARNING: Perl module Spreadsheet::XLSX cannot be loaded.
+WARNING: Microsoft Excel 2007 'XLSX' formatted files will not be processed.
> example.3
X1 X2001.01.01 X1.01 X0.205818150587141 X.DIV.0. A
1 2 2002-02-02 2:02 0.2910708 NA B
@@ -548,6 +572,9 @@
9 10 2010-10-10 10:10 0.6508541 0.0000000 A
>
> example.4 <- read.xls(exampleFile, sheet=3) # second worksheet by number
+WARNING: Perl module Compress::Raw::Zlib cannot be loaded.
+WARNING: Perl module Spreadsheet::XLSX cannot be loaded.
+WARNING: Microsoft Excel 2007 'XLSX' formatted files will not be processed.
> example.4
X1 X2001.01.01 X1.01 X0.205818150587141 X.DIV.0. A
1 2 2002-02-02 2:02 0.2910708 NA B
@@ -560,68 +587,28 @@
8 9 2009-09-09 9:09 0.6174545 0.0000000 A
9 10 2010-10-10 10:10 0.6508541 0.0000000 A
>
-> example.x.1 <- read.xls(exampleFile2007, sheet=1) # default is first worksheet
-> example.x.1
- A B C
-1 1 1 1
-2 2 4 8
-3 3 9 27
-4 4 16 64
-5 5 25 125
-6 6 36 216
-7 7 49 343
+> if( 'XLSX' %in% xlsFormats() )
++ {
++ example.x.1 <- read.xls(exampleFile2007, sheet=1) # default is first worksheet
++ print(example.x.1)
++
++ 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
++ print(example.x.3)
++
++ example.x.4 <- read.xls(exampleFile2007, sheet=3) # second worksheet by number
++ print(example.x.4)
++
++ data <- read.xls(exampleFile2007, sheet="Sheet Second") # and by name
++ print(data)
++
++ # load the third worksheet, skipping the first two non-data lines...
++ data <- read.xls(exampleFile2007, sheet="Sheet with initial text", skip=2)
++ print(data)
++ }
>
-> example.x.2 <- read.xls(exampleFile2007, sheet=2) # second worksheet by number
-> example.x.2
- X D E F G Factor
-1 FirstRow 1 NA NA NA Red
-2 SecondRow 2 1 NA NA Green
-3 ThirdRow 3 2 1 NA Red
-4 FourthRow 4 3 2 1 Black
->
-> example.x.3 <- read.xls(exampleFile2007, sheet=3) # second worksheet by number
-> example.x.3
- X1 X2001.01.01 X1.01 X0.205818150587141 X.DIV.0. A
-1 2 2002-02-02 2:02 0.2910708 NA B
-2 3 2003-03-03 3:03 0.3564875 -0.8414710 C
-3 4 2004-04-04 4:04 0.4116363 0.7080734
-4 5 2005-05-05 5:05 0.4602234 0.5013680 A
-5 6 2006-06-06 6:06 NA 0.2513698 B
-6 7 2007-07-07 7:07 0.5445436 0.0631868 B
-7 8 2008-08-08 8:08 0.5821416 NA C
-8 9 2009-09-09 9:09 0.6174545 0.0000000 A
-9 10 2010-10-10 10:10 0.6508541 0.0000000 A
->
-> example.x.4 <- read.xls(exampleFile2007, sheet=3) # second worksheet by number
-> example.x.4
- X1 X2001.01.01 X1.01 X0.205818150587141 X.DIV.0. A
-1 2 2002-02-02 2:02 0.2910708 NA B
-2 3 2003-03-03 3:03 0.3564875 -0.8414710 C
-3 4 2004-04-04 4:04 0.4116363 0.7080734
-4 5 2005-05-05 5:05 0.4602234 0.5013680 A
-5 6 2006-06-06 6:06 NA 0.2513698 B
-6 7 2007-07-07 7:07 0.5445436 0.0631868 B
-7 8 2008-08-08 8:08 0.5821416 NA C
-8 9 2009-09-09 9:09 0.6174545 0.0000000 A
-9 10 2010-10-10 10:10 0.6508541 0.0000000 A
->
-> data <- read.xls(exampleFile2007, sheet="Sheet Second") # and by name
-> data
- X D E F G Factor
-1 FirstRow 1 NA NA NA Red
-2 SecondRow 2 1 NA NA Green
-3 ThirdRow 3 2 1 NA Red
-4 FourthRow 4 3 2 1 Black
->
-> # load the third worksheet, skipping the first two non-data lines...
-> data <- read.xls(exampleFile2007, sheet="Sheet with initial text", skip=2)
-> data
- X X.1 D E F G Factor
-1 NA FirstRow 1 NA NA NA Red
-2 NA SecondRow 2 1 NA NA Green
-3 NA ThirdRow 3 2 1 NA Red
-4 NA FourthRow 4 3 2 1 Black
->
> proc.time()
user system elapsed
- 2.787 2.477 3.347
+ 1.350 0.285 1.659
Modified: trunk/gdata/tests/tests.write.fwf.Rout.save
===================================================================
--- trunk/gdata/tests/tests.write.fwf.Rout.save 2010-05-01 22:14:05 UTC (rev 1434)
+++ trunk/gdata/tests/tests.write.fwf.Rout.save 2010-05-02 06:11:26 UTC (rev 1435)
@@ -27,7 +27,7 @@
Attaching package: 'gdata'
- The following object(s) are masked from package:utils :
+The following object(s) are masked from package:utils :
object.size
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|