Thread: [R-gregmisc-users] SF.net SVN: r-gregmisc:[1305] trunk/gdata
Brought to you by:
warnes
From: <gg...@us...> - 2008-12-20 22:35:01
|
Revision: 1305 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1305&view=rev Author: ggorjan Date: 2008-12-20 22:34:57 +0000 (Sat, 20 Dec 2008) Log Message: ----------- Modified Paths: -------------- trunk/gdata/NAMESPACE trunk/gdata/inst/NEWS Added Paths: ----------- trunk/gdata/R/trimSum.R trunk/gdata/inst/unitTests/runit.trimSum.R trunk/gdata/man/trimSum.Rd Modified: trunk/gdata/NAMESPACE =================================================================== --- trunk/gdata/NAMESPACE 2008-12-20 22:28:35 UTC (rev 1304) +++ trunk/gdata/NAMESPACE 2008-12-20 22:34:57 UTC (rev 1305) @@ -23,6 +23,7 @@ reorder.factor, resample, trim, + trimSum, unmatrix, upperTriangle, "upperTriangle<-", Added: trunk/gdata/R/trimSum.R =================================================================== --- trunk/gdata/R/trimSum.R (rev 0) +++ trunk/gdata/R/trimSum.R 2008-12-20 22:34:57 UTC (rev 1305) @@ -0,0 +1,37 @@ +### trimSum.R +###------------------------------------------------------------------------ +### What: Sum trimmed values - code +### $Id$ +### Time-stamp: <2008-12-20 12:11:27 ggorjan> +###------------------------------------------------------------------------ + +trimSum <- function(x, n, right=TRUE, na.rm=FALSE, ...) +{ + ## --- Setup --- + + if(!is.vector(x) | is.list(x)) + stop("'x' must be a vector - for now") + if(!is.numeric(x)) + stop("'x' must be numeric") + if(length(x) <= n) + stop("'n' must be smaller than the length of x") + + ## --- Trim --- + + N <- length(x) + if(right) { + x2 <- x[1:n] + x2[n] <- sum(x[n:N], na.rm=na.rm) + } else { + k <- (N - n + 1) + x2 <- x[k:N] + x2[1] <- sum(x[1:k], na.rm=na.rm) + } + + ## --- Return --- + + x2 +} + +###------------------------------------------------------------------------ +### trimSum.R ends here Modified: trunk/gdata/inst/NEWS =================================================================== --- trunk/gdata/inst/NEWS 2008-12-20 22:28:35 UTC (rev 1304) +++ trunk/gdata/inst/NEWS 2008-12-20 22:34:57 UTC (rev 1305) @@ -1,6 +1,8 @@ CHANGES IN 2.5.0 (2008-??-??) ----------------------------- +- New function trimSum that sums trimmed values + - New function cbindX that can bind objects with different number of rows. - write.fwf gains width argument. Unknown values can increase or decrease Added: trunk/gdata/inst/unitTests/runit.trimSum.R =================================================================== --- trunk/gdata/inst/unitTests/runit.trimSum.R (rev 0) +++ trunk/gdata/inst/unitTests/runit.trimSum.R 2008-12-20 22:34:57 UTC (rev 1305) @@ -0,0 +1,61 @@ +### runit.trimSum.R +###------------------------------------------------------------------------ +### What: Unit tests for trimSum +### $Id$ +### Time-stamp: <2008-12-20 11:58:50 ggorjan> +###------------------------------------------------------------------------ + +### {{{ --- Test setup --- + +if(FALSE) { + library("RUnit") + library("gdata") +} + +### }}} +### {{{ --- trimSum --- + +test.trimSum <- function() +{ + + ## 'x' must be a vector - for now + checkException(trimSum(matrix(1:10))) + checkException(trimSum(data.frame(1:10))) + checkException(trimSum(list(1:10))) + + ## 'x' must be numeric + checkException(trimSum(letters)) + + ## 'n' must be smaller than the length of x + checkException(trimSum(x=1:10, n=11)) + checkException(trimSum(x=1, n=1)) + + ## Default + x <- trimSum(x=1:10, n=5) + x2 <- c(1:4, 45) + checkEquals(x, x2) + + ## Left + x <- trimSum(x=1:10, n=5, right=FALSE) + x2 <- c(21, 7:10) + checkEquals(x, x2) + + ## NA + x <- trimSum(x=c(1:9, NA), n=5) + x2 <- c(1:4, NA) + checkEquals(x, x2) + + x <- trimSum(x=c(1:9, NA), n=5, na.rm=TRUE) + x2 <- c(1:4, 35) + checkEquals(x, x2) +} + +### }}} +### {{{ Dear Emacs +## Local variables: +## folded-file: t +## End: +### }}} + +###------------------------------------------------------------------------ +### runit.trimSum.R ends here Added: trunk/gdata/man/trimSum.Rd =================================================================== --- trunk/gdata/man/trimSum.Rd (rev 0) +++ trunk/gdata/man/trimSum.Rd 2008-12-20 22:34:57 UTC (rev 1305) @@ -0,0 +1,52 @@ +% trimSum.Rd +%-------------------------------------------------------------------------- +% What: Sum trimmed values - help +% $Id$ +% Time-stamp: <2008-12-20 00:15:57 ggorjan> +%-------------------------------------------------------------------------- + +\name{trimSum} + +\alias{trimSum} + +\title{Trim a vector such that the last/first value represents the sum of + trimmed values} + +\description{\code{trimSum} trims (shortens) a vector in such a way that + the last or first value represents the sum of trimmed values. User needs + to specify the desired length of a trimmed vector. +} + +\usage{trimSum(x, n, right=TRUE, na.rm=FALSE, \ldots)} + +\arguments{ + \item{x}{numeric, a vector of numeric values} + \item{n}{numeric, desired length of the output} + \item{right}{logical, trim on the right/bottom or the left/top side} + \item{na.rm}{logical, remove \code{NA} values when applying a function} + \item{\ldots}{arguments passed to other methods - currently not used} +} + +\value{Trimmed vector with a last/first value representing the sum of + trimmed values} + +\author{Gregor Gorjanc} + +\seealso{\code{\link[gdata]{trim}}} + +\examples{ + +x <- 1:10 +trimSum(x, n=5) +trimSum(x, n=5, right=FALSE) + +x[9] <- NA +trimSum(x, n=5) +trimSum(x, n=5, na.rm=TRUE) + +} + +\keyword{manip} + +%-------------------------------------------------------------------------- +% trimSum.Rd ends here This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gg...@us...> - 2008-12-31 13:24:53
|
Revision: 1306 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1306&view=rev Author: ggorjan Date: 2008-12-31 13:24:42 +0000 (Wed, 31 Dec 2008) Log Message: ----------- New function .runRUnitTestsGdata that enables run of all RUnit tests during the R CMD check as well as directly from within R. Modified Paths: -------------- trunk/gdata/inst/unitTests/Makefile trunk/gdata/man/gdata-package.Rd Added Paths: ----------- trunk/gdata/R/runRUnitTests.R trunk/gdata/inst/unitTests/runRUnitTests.R trunk/gdata/man/runRUnitTests.Rd Removed Paths: ------------- trunk/gdata/tests/doRUnit.R Added: trunk/gdata/R/runRUnitTests.R =================================================================== --- trunk/gdata/R/runRUnitTests.R (rev 0) +++ trunk/gdata/R/runRUnitTests.R 2008-12-31 13:24:42 UTC (rev 1306) @@ -0,0 +1,27 @@ +### runRUnitTests.R +###------------------------------------------------------------------------ +### What: Run RUnit tests (wrapper function) - R code +### $Id$ +### Time-stamp: <2008-12-30 20:59:11 ggorjan> +###------------------------------------------------------------------------ + +.runRUnitTestsGdata <- function(testFileRegexp="^runit.+\\.[rR]$") +{ + ## Setup + .pkg <- environmentName(environment(.runRUnitTestsGdata)) + .path <- system.file("unitTests", package=.pkg) + .suite <- file.path(.path, "runRUnitTests.R") + + ## Some checks + stopifnot(file.exists(.path), + file.info(path.expand(.path))$isdir, + file.exists(.suite)) + + ## Run the suite + .way <- "function" + source(.suite, local=TRUE) + ## local=TRUE since .pkg and other vars do not exists in .suite environment +} + +###------------------------------------------------------------------------ +### runRUnitTests.R ends here Property changes on: trunk/gdata/R/runRUnitTests.R ___________________________________________________________________ Added: svn:keywords + Modified: trunk/gdata/inst/unitTests/Makefile =================================================================== --- trunk/gdata/inst/unitTests/Makefile 2008-12-20 22:34:57 UTC (rev 1305) +++ trunk/gdata/inst/unitTests/Makefile 2008-12-31 13:24:42 UTC (rev 1306) @@ -1,18 +1,16 @@ TOP=../.. PKG=${shell cd ${TOP};pwd} -SUITE=doRUnit.R -R=${R_HOME}/bin/R +SUITE=runRUnitTests.R +R=R -all: inst test +test: # Run unit tests + ${R} --vanilla --slave < ${SUITE} inst: # Install package cd ${TOP}/..;\ ${R} CMD INSTALL ${PKG} -test: # Run unit tests - export RCMDCHECK=FALSE;\ - cd ${TOP}/tests;\ - ${R} --vanilla --slave < ${SUITE} +all: inst test echo: # Echo env. variables @echo "Package folder: ${PKG}" Added: trunk/gdata/inst/unitTests/runRUnitTests.R =================================================================== --- trunk/gdata/inst/unitTests/runRUnitTests.R (rev 0) +++ trunk/gdata/inst/unitTests/runRUnitTests.R 2008-12-31 13:24:42 UTC (rev 1306) @@ -0,0 +1,104 @@ +### runRUnitTests.R +###------------------------------------------------------------------------ +### What: Run RUnit tests (the core)- R code +### $Id$ +### Time-stamp: <2008-12-30 12:52:51 ggorjan> +###------------------------------------------------------------------------ + +## The setup seems to be quite messy, but it is so to enable use of this in +## several ways as shown bellow. + +## "R CMD check" way should be the most authoritative way to run the RUnit +## tests for a developer. RUnit tests are issued during R CMD check of the +## package due to example section of .runRUnitTests() function. If any test +## fails (failure) or if there are any R errors during RUnit testing, R CMD +## check fails. These are variable values specific for this way: +## - .path DEVEL/PATH/PKG.Rcheck/PKG/unitTests +## - .way function + +## ".runRUnitTests()" way from within R after library(PKG) is handy for +## package useRs, since it enables useRs to be sure that all tests pass for +## their installation. This is just a convenient wrapper function to run +## the RUnit testing suite. These are variable values specific for this +## way: +## - .path INSTALL/PATH/PKG/unitTests +## - .way function + +## "Shell" way is another possibility mainly for a developer in order to +## skip possibly lengthy R CMD check and perform just RUnit testing with an +## installed version of a pcakage. These are variable values specific for +## this way: +## - .path DEVEL/PATH/PKG/inst/unitTests +## - .way shell +## +## Rscript runRUnitTests.R +## R CMD BATCH runRUnitTests.R +## make +## make all + +## Sourced via shell (Makefile, Rscript, R CMD BATCH) +if(!exists(".pkg")) { + .path <- getwd() + .way <- "shell" + .pkg <- c(read.dcf(file="../../DESCRIPTION", fields="Package")) + print(.pkg) + testFileRegexp <- "^base.+\\.[rR]$" +} + +if(require("RUnit", quietly=TRUE)) { + + ## Debugging echo + cat("\nRunning RUnit tests\n") + print(list(pkg=.pkg, getwd=getwd(), pathToRUnitTests=.path)) + + ## Load the package - not needed for .runRUnitTests() + if(.way %in% c("shell")) + library(package=.pkg, character.only=TRUE) + + ## Define tests + testSuite <- defineTestSuite(name=paste(.pkg, "RUnit testing"), + dirs=.path, testFileRegexp=testFileRegexp) + + ## Run + tests <- runTestSuite(testSuite) + + if(file.access(.path, 02) != 0) { + ## cannot write to .path -> use writable one + tdir <- tempfile(paste(.pkg, "RUnitTests", sep="_")) + dir.create(tdir) + pathReport <- file.path(tdir, "report") + } else { + pathReport <- file.path(.path, "report") + } + + ## Print results: + printTextProtocol(tests) + printTextProtocol(tests, + fileName=paste(pathReport, ".txt", sep="")) + + ## Print HTML Version of results: + printHTMLProtocol(tests, + fileName=paste(pathReport, ".html", sep="")) + + cat("\nRUnit reports also written to\n", + pathReport, ".(txt|html)\n\n", sep="") + + ## Return stop() to cause R CMD check stop in case of + ## - failures i.e. FALSE to RUnit tests or + ## - errors i.e. R errors + tmp <- getErrors(tests) + if(tmp$nFail > 0 || tmp$nErr > 0) { + stop(paste("\n\nRUnit testing failed:\n", + " - #test failures: ", tmp$nFail, "\n", + " - #R errors: ", tmp$nErr, "\n\n", sep="")) + } + +} else { + + cat("R package 'RUnit' cannot be loaded - no unit tests run\n", + "for package", .pkg,"\n") + +} + +###------------------------------------------------------------------------ +### runRUnitTests.R ends here Property changes on: trunk/gdata/inst/unitTests/runRUnitTests.R ___________________________________________________________________ Added: svn:keywords + Modified: trunk/gdata/man/gdata-package.Rd =================================================================== --- trunk/gdata/man/gdata-package.Rd 2008-12-20 22:34:57 UTC (rev 1305) +++ trunk/gdata/man/gdata-package.Rd 2008-12-31 13:24:42 UTC (rev 1306) @@ -32,4 +32,13 @@ } +\section{Testing}{ + +If you want to perform the validity/unit testing of the installed +\pkg{ggmisc} package on your own computer, take a look at +\code{\link{.runRUnitTestsGdata}} function - please note that +you need the \pkg{RUnit} package for this to work. + +} + \keyword{package} \ No newline at end of file Added: trunk/gdata/man/runRUnitTests.Rd =================================================================== --- trunk/gdata/man/runRUnitTests.Rd (rev 0) +++ trunk/gdata/man/runRUnitTests.Rd 2008-12-31 13:24:42 UTC (rev 1306) @@ -0,0 +1,54 @@ +% runRUnitTests.Rd +%-------------------------------------------------------------------------- +% What: Run RUnit tests - help +% $Id$ +% Time-stamp: <2008-12-30 20:58:26 ggorjan> +%-------------------------------------------------------------------------- + +\name{.runRUnitTestsGdata} +\alias{.runRUnitTestsGdata} + +\title{Run RUnit tests for the gdata package} + +\description{ + +Run \pkg{RUnit} tests to perform the validity/unit testing of installed +\pkg{gdata} package on your own computer. + +} + +\usage{.runRUnitTestsGdata(testFileRegexp="^runit.+\\\\.[rR]$")} + +\arguments{ + \item{testFileRegexp}{regular expression; see details} +} + +\details{ + +Argument \code{testFileRegexp} can be used to specify different sets of +tests provided by the package. The following values are sensible: +\itemize{ + \item \code{"^runit.+\\\\.[rR]$"} for basic tests +} + +} + +\value{ + +None, just the print out of \pkg{RUnit} testing. + +} + +\seealso{ + \code{\link[RUnit]{defineTestSuite}} in \pkg{RUnit} package +} + +\examples{ + ## Basic testing + .runRUnitTestsGdata() +} + +\keyword{misc} + +%-------------------------------------------------------------------------- +% runRUnitTests.Rd ends here Deleted: trunk/gdata/tests/doRUnit.R =================================================================== --- trunk/gdata/tests/doRUnit.R 2008-12-20 22:34:57 UTC (rev 1305) +++ trunk/gdata/tests/doRUnit.R 2008-12-31 13:24:42 UTC (rev 1306) @@ -1,63 +0,0 @@ -### doRUnit.R -###------------------------------------------------------------------------ -### What: Run unit tests with RUnit -### $Id$ -### Time-stamp: <2007-06-06 14:02:41 ggorjan> -###------------------------------------------------------------------------ - -## unit tests will not be done if RUnit is not available -if(require("RUnit", quietly=TRUE)) { - - ## --- Setup --- - - pkg <- "gdata" - if(Sys.getenv("RCMDCHECK") == "FALSE") { - ## Path to unit tests for standalone running under Makefile (not R CMD check) - ## PKG/tests/../inst/unitTests - path <- file.path(getwd(), "..", "inst", "unitTests") - } else { - ## Path to unit tests for R CMD check - ## PKG.Rcheck/tests/../PKG/unitTests - path <- system.file(package=pkg, "unitTests") - } - cat("\nRunning unit tests\n") - print(list(pkg=pkg, getwd=getwd(), pathToUnitTests=path)) - - library(package=pkg, character.only=TRUE) - - ## --- Testing --- - - ## Define tests - testSuite <- defineTestSuite(name=paste(pkg, "unit testing"), - dirs=path) - ## Run - tests <- runTestSuite(testSuite) - - ## Default report name - pathReport <- file.path(path, "report") - - ## Report to stdout and text files - cat("------------------- UNIT TEST SUMMARY ---------------------\n\n") - printTextProtocol(tests, showDetails=FALSE) - printTextProtocol(tests, showDetails=FALSE, - fileName=paste(pathReport, "Summary.txt", sep="")) - printTextProtocol(tests, showDetails=TRUE, - fileName=paste(pathReport, ".txt", sep="")) - - ## Report to HTML file - printHTMLProtocol(tests, fileName=paste(pathReport, ".html", sep="")) - - ## Return stop() to cause R CMD check stop in case of - ## - failures i.e. FALSE to unit tests or - ## - errors i.e. R errors - tmp <- getErrors(tests) - if(tmp$nFail > 0 | tmp$nErr > 0) { - stop(paste("\n\nunit testing failed (#test failures: ", tmp$nFail, - ", #R errors: ", tmp$nErr, ")\n\n", sep="")) - } -} else { - warning("cannot run unit tests -- package RUnit is not available") -} - -###------------------------------------------------------------------------ -### doRUnit.R ends here This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gg...@us...> - 2008-12-31 13:26:03
|
Revision: 1307 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1307&view=rev Author: ggorjan Date: 2008-12-31 13:25:52 +0000 (Wed, 31 Dec 2008) Log Message: ----------- New function bindData that binds two data frames into a multivariate data frame in a different way than merge. Added Paths: ----------- trunk/gdata/R/bindData.R trunk/gdata/inst/unitTests/runit.bindData.R trunk/gdata/man/bindData.Rd Added: trunk/gdata/R/bindData.R =================================================================== --- trunk/gdata/R/bindData.R (rev 0) +++ trunk/gdata/R/bindData.R 2008-12-31 13:25:52 UTC (rev 1307) @@ -0,0 +1,38 @@ +### bindData.R +###------------------------------------------------------------------------ +### What: Bind two data frames - code +### $Id$ +### Time-stamp: <2008-12-30 22:01:00 ggorjan> +###------------------------------------------------------------------------ + +bindData <- function(x, y, common) +{ + ## --- Setup --- + if(!is.data.frame(x)) stop("'x' must be a data frame") + if(!is.data.frame(y)) stop("'y' must be a data frame") + + ## --- New data frame --- + + ## First add common column and a dataset indicator column + z <- rbind(x[common], y[common]) + + ## Other columns + ## - remove common columns in x and y + namesz <- names(z) + otherx <- names(x) + otherx <- otherx[!(otherx %in% namesz)] + othery <- names(y) + othery <- othery[!(othery %in% namesz)] + + ## - add all other columns but as a set for each input data frame + rx <- nrow(x); cx <- length(otherx) + ry <- nrow(y); cy <- length(othery) + + z <- cbind(z, rbind(x[otherx], matrix(rep(NA, times=(ry * cx)), nrow=ry, ncol=cx, dimnames=list(NULL, otherx)))) + z <- cbind(z, rbind(matrix(rep(NA, times=(rx * cy)), nrow=rx, ncol=cy, dimnames=list(NULL, othery)), y[othery])) + + z +} + +###------------------------------------------------------------------------ +### bindData.R ends here Property changes on: trunk/gdata/R/bindData.R ___________________________________________________________________ Added: svn:keywords + Added: trunk/gdata/inst/unitTests/runit.bindData.R =================================================================== --- trunk/gdata/inst/unitTests/runit.bindData.R (rev 0) +++ trunk/gdata/inst/unitTests/runit.bindData.R 2008-12-31 13:25:52 UTC (rev 1307) @@ -0,0 +1,75 @@ +### runit.bindData.R +###------------------------------------------------------------------------ +### What: Bind two data frames - unit tests +### $Id$ +### Time-stamp: <2008-12-30 11:58:50 ggorjan> +###------------------------------------------------------------------------ + +### {{{ --- Test setup --- + +if(FALSE) { + library("RUnit") + library("gdata") +} + +### }}} +### {{{ --- bindData --- + +test.bindData <- function() +{ + ## 'x'/'y' must be a data.frame + checkException(bindData(x=1:10, y=1:10)) + checkException(bindData(x=matrix(1:10), y=matrix(1:10))) + + n1 <- 6; n2 <- 12; n3 <- 4 + ## Single trait 1 + num <- c(5:n1, 10:13) + tmp1 <- data.frame(y1=rnorm(n=n1), + f1=factor(rep(c("A", "B"), n1/2)), + ch=letters[num], + fa=factor(letters[num]), + nu=(num) + 0.5, + id=factor(num), stringsAsFactors=FALSE) + + ## Single trait 2 with repeated records, some subjects also in tmp1 + num <- 4:9 + tmp2 <- data.frame(y2=rnorm(n=n2), + f2=factor(rep(c("C", "D"), n2/2)), + ch=letters[rep(num, times=2)], + fa=factor(letters[rep(c(num), times=2)]), + nu=c((num) + 0.5, (num) + 0.25), + id=factor(rep(num, times=2)), stringsAsFactors=FALSE) + + ## Single trait 3 with completely distinct set of subjects + num <- 1:4 + tmp3 <- data.frame(y3=rnorm(n=n3), + f3=factor(rep(c("E", "F"), n3/2)), + ch=letters[num], + fa=factor(letters[num]), + nu=(num) + 0.5, + id=factor(num), stringsAsFactors=FALSE) + + ## Combine all datasets + tmp12 <- bindData(x=tmp1, y=tmp2, common=c("id", "nu", "ch", "fa")) + tmp123 <- bindData(x=tmp12, y=tmp3, common=c("id", "nu", "ch", "fa")) + + checkEquals(names(tmp123), c("id", "nu", "ch", "fa", "y1", "f1", "y2", "f2", "y3", "f3")) + checkEquals(rbind(tmp1["id"], tmp2["id"], tmp3["id"]), tmp123["id"]) + checkEquals(rbind(tmp1["fa"], tmp2["fa"], tmp3["fa"]), tmp123["fa"]) + checkEquals(is.na(tmp123$y1), c(rep(FALSE, times=n1), rep(TRUE, times=n2+n3))) + checkEquals(is.na(tmp123$f1), c(rep(FALSE, times=n1), rep(TRUE, times=n2+n3))) + checkEquals(is.na(tmp123$y2), c(rep(TRUE, times=n1), rep(FALSE, times=n2), rep(TRUE, times=n3))) + checkEquals(is.na(tmp123$f2), c(rep(TRUE, times=n1), rep(FALSE, times=n2), rep(TRUE, times=n3))) + checkEquals(is.na(tmp123$y3), c(rep(TRUE, times=n1+n2), rep(FALSE, times=n3))) + checkEquals(is.na(tmp123$f3), c(rep(TRUE, times=n1+n2), rep(FALSE, times=n3))) +} + +### }}} +### {{{ Dear Emacs +## Local variables: +## folded-file: t +## End: +### }}} + +###------------------------------------------------------------------------ +### runit.bindData.R ends here Property changes on: trunk/gdata/inst/unitTests/runit.bindData.R ___________________________________________________________________ Added: svn:keywords + Added: trunk/gdata/man/bindData.Rd =================================================================== --- trunk/gdata/man/bindData.Rd (rev 0) +++ trunk/gdata/man/bindData.Rd 2008-12-31 13:25:52 UTC (rev 1307) @@ -0,0 +1,93 @@ +% bindData.Rd +%-------------------------------------------------------------------------- +% What: Bind two data frames - help +% $Id$ +% Time-stamp: <2008-12-30 13:49:50 ggorjan> +%-------------------------------------------------------------------------- + +\name{bindData} +\alias{bindData} + +\title{Bind two data frames into a multivariate data frame} + +\description{ + Usually data frames represent one set of variables and one needs to + bind/join them for multivariate analysis. When \code{\link{merge}} is not + the approriate solution, \code{bindData} might perform an appropriate binding + for two data frames. This is especially usefull when some variables are + measured once, while others are repeated. +} + +\usage{ + bindData(x, y, common) +} + +\arguments{ + \item{x}{data.frame} + \item{y}{data.frame} + \item{common}{character, list of column names that are common to both + input data frames} +} + +\details{ + Data frames are joined in a such a way, that the new data frame has + \eqn{c + (n_1 - c) + (n_2 - c)} columns, where \eqn{c} is the number of + common columns, and \eqn{n_1} and \eqn{n_2} are the number of columns + in the first and in the second data frame, respectively. +} + +\value{ + A data frame. +} + +\author{Gregor Grojanc} + +\seealso{ + \code{\link[base]{merge}}, + \code{\link{wideByFactor}} +} + +\examples{ +n1 <- 6 +n2 <- 12 +n3 <- 4 +## Single trait 1 +num <- c(5:n1, 10:13) +(tmp1 <- data.frame(y1=rnorm(n=n1), + f1=factor(rep(c("A", "B"), n1/2)), + ch=letters[num], + fa=factor(letters[num]), + nu=(num) + 0.5, + id=factor(num), stringsAsFactors=FALSE)) + +## Single trait 2 with repeated records, some subjects also in tmp1 +num <- 4:9 +(tmp2 <- data.frame(y2=rnorm(n=n2), + f2=factor(rep(c("C", "D"), n2/2)), + ch=letters[rep(num, times=2)], + fa=factor(letters[rep(c(num), times=2)]), + nu=c((num) + 0.5, (num) + 0.25), + id=factor(rep(num, times=2)), stringsAsFactors=FALSE)) + +## Single trait 3 with completely distinct set of subjects +num <- 1:4 +(tmp3 <- data.frame(y3=rnorm(n=n3), + f3=factor(rep(c("E", "F"), n3/2)), + ch=letters[num], + fa=factor(letters[num]), + nu=(num) + 0.5, + id=factor(num), stringsAsFactors=FALSE)) + +## Combine all datasets +(tmp12 <- bindData(x=tmp1, y=tmp2, common=c("id", "nu", "ch", "fa"))) +(tmp123 <- bindData(x=tmp12, y=tmp3, common=c("id", "nu", "ch", "fa"))) + +## Sort by subject +tmp123[order(tmp123$ch), ] +} + +\keyword{manip} +\keyword{misc} + +%-------------------------------------------------------------------------- +% bindData.Rd ends here \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gg...@us...> - 2008-12-31 13:27:01
|
Revision: 1308 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1308&view=rev Author: ggorjan Date: 2008-12-31 13:26:51 +0000 (Wed, 31 Dec 2008) Log Message: ----------- New functions getYear, getMonth, getDay, getHour, getMin, and getSec for extracting the date/time parts from objects of a date/time class. Added Paths: ----------- trunk/gdata/R/getDateTimeParts.R trunk/gdata/inst/unitTests/runit.getDateTimeParts.R trunk/gdata/man/getDateTimePart.Rd Added: trunk/gdata/R/getDateTimeParts.R =================================================================== --- trunk/gdata/R/getDateTimeParts.R (rev 0) +++ trunk/gdata/R/getDateTimeParts.R 2008-12-31 13:26:51 UTC (rev 1308) @@ -0,0 +1,90 @@ +### getDateTimePart.R +###------------------------------------------------------------------------ +### What: Extract date and time parts from various date and time classes +### $Id$ +### Time-stamp: <2008-12-30 22:42:58 ggorjan> +###------------------------------------------------------------------------ + +### {{{ getYear +###------------------------------------------------------------------------ + +getYear <- function(x, format, ...) + UseMethod("getYear") + +getYear.default <- function(x, format, ...) + stop("'getYear' can only be used on objects of a date/time class") + +getYear.Date <- +getYear.POSIXct <- +getYear.POSIXlt <- function(x, format="%Y", ...) + format(x=x, format=format, ...) + +### }}} +### {{{ getMonth +###------------------------------------------------------------------------ + +getMonth <- function(x, format, ...) + UseMethod("getMonth") + +getMonth.default <- function(x, format, ...) + stop("'getMonth' can only be used on objects of a date/time class") + +getMonth.Date <- +getMonth.POSIXct <- +getMonth.POSIXlt <- function(x, format="%m", ...) + format(x=x, format=format) + +### }}} +### {{{ getDay +###------------------------------------------------------------------------ + +getDay <- function(x, format, ...) + UseMethod("getDay") + +getDay.default <- function(x, format, ...) + stop("'getDay' can only be used on objects of a date/time class") + +getDay.Date <- +getDay.POSIXct <- +getDay.POSIXlt <- function(x, format="%d", ...) + format(x=x, format=format) + +### }}} +### {{{ getHour +###------------------------------------------------------------------------ + +getHour <- function(x, format, ...) + UseMethod("getHour") + +getHour.default <- function(x, format, ...) + stop("'getHour' can only be used on objects of a date/time class") + +### }}} +### {{{ getMin +###------------------------------------------------------------------------ + +getMin <- function(x, format, ...) + UseMethod("getMin") + +getMin.default <- function(x, format, ...) + stop("'getMin' can only be used on objects of a date/time class") + +### }}} +### {{{ getSec +###------------------------------------------------------------------------ + +getSec <- function(x, format, ...) + UseMethod("getSec") + +getSec.default <- function(x, format, ...) + stop("'getSec' can only be used on objects of a date/time class") + +### }}} +### {{{ Dear Emacs +## Local variables: +## folded-file: t +## End: +### }}} + +###------------------------------------------------------------------------ +### getDateTimePart.R ends here \ No newline at end of file Property changes on: trunk/gdata/R/getDateTimeParts.R ___________________________________________________________________ Added: svn:keywords + Added: trunk/gdata/inst/unitTests/runit.getDateTimeParts.R =================================================================== --- trunk/gdata/inst/unitTests/runit.getDateTimeParts.R (rev 0) +++ trunk/gdata/inst/unitTests/runit.getDateTimeParts.R 2008-12-31 13:26:51 UTC (rev 1308) @@ -0,0 +1,121 @@ +### runit.getDateTimeParts.R +###------------------------------------------------------------------------ +### What: Extract date and time parts from ... - unit tests +### $Id$ +### Time-stamp: <2008-12-30 22:41:18 ggorjan> +###------------------------------------------------------------------------ + +### {{{ --- Test setup --- + +if(FALSE) { + library("RUnit") + library("gdata") +} + +num <- 1 +cha <- "a" +fac <- factor(c("A")) + +tYear <- as.character(c(2006, 1995, 1005, 3067)) +tMonth <- c("01", "04", "06", "12") +tDay <- c("01", "12", "22", "04") +tDate <- paste(tYear, tMonth, tDay, sep="-") + +tHour <- c("05", "16", "20", "03") +tMin <- c("16", "40", "06", "52") +tSec <- c("56", "34", "05", "15") +tTime <- paste(tHour, tMin, tSec, sep=":") + +# tDateTime <- paste() + +cDate <- as.Date(tDate) +cDatePOSIXct <- as.POSIXct(cDate) +cDatePOSIXlt <- as.POSIXlt(cDate) + +### }}} +### {{{ --- getYear --- + +test.getYear <- function() +{ + checkException(getYear(x=num)) + checkException(getYear(x=cha)) + checkException(getYear(x=fac)) + + checkIdentical(getYear(x=cDate), tYear) + checkIdentical(getYear(x=cDatePOSIXct), tYear) + checkIdentical(getYear(x=cDatePOSIXlt), tYear) +} + +### }}} +### {{{ --- getMonth --- + +test.getMonth <- function() +{ + checkException(getMonth(x=num)) + checkException(getMonth(x=cha)) + checkException(getMonth(x=fac)) + + checkIdentical(getMonth(x=cDate), tMonth) + checkIdentical(getMonth(x=cDatePOSIXct), tMonth) + checkIdentical(getMonth(x=cDatePOSIXlt), tMonth) +} + +### }}} +### {{{ --- getDay --- + +test.getDay <- function() +{ + checkException(getDay(x=num)) + checkException(getDay(x=cha)) + checkException(getDay(x=fac)) + + checkIdentical(getDay(x=cDate), tDay) + checkIdentical(getDay(x=cDatePOSIXct), tDay) + checkIdentical(getDay(x=cDatePOSIXlt), tDay) +} + +### }}} +### {{{ --- getHour --- + +test.getHour <- function() +{ + checkException(getHour(x=num)) + checkException(getHour(x=cha)) + checkException(getHour(x=fac)) + +## checkIdentical(getHour(x=cDate), tHour) +} + +### }}} +### {{{ --- getMin --- + +test.getMin <- function() +{ + checkException(getMin(x=num)) + checkException(getMin(x=cha)) + checkException(getMin(x=fac)) + +## checkIdentical(getMin(x=cDate), tMin) +} + +### }}} +### {{{ --- getSec --- + +test.getSec <- function() +{ + checkException(getSec(x=num)) + checkException(getSec(x=cha)) + checkException(getSec(x=fac)) + +## checkIdentical(getSec(x=cDate), tSec) +} + +### }}} +### {{{ Dear Emacs +### Local variables: +### folded-file: t +### end: +### }}} + +###------------------------------------------------------------------------ +### runit.getDateTimeParts.R ends here Property changes on: trunk/gdata/inst/unitTests/runit.getDateTimeParts.R ___________________________________________________________________ Added: svn:keywords + Added: trunk/gdata/man/getDateTimePart.Rd =================================================================== --- trunk/gdata/man/getDateTimePart.Rd (rev 0) +++ trunk/gdata/man/getDateTimePart.Rd 2008-12-31 13:26:51 UTC (rev 1308) @@ -0,0 +1,106 @@ +% getDateTimeParts.Rd +%-------------------------------------------------------------------------- +% What: Extract date and time parts from ... - help +% $Id$ +% Time-stamp: <2008-12-30 22:44:20 ggorjan> +%-------------------------------------------------------------------------- + +\name{getYear} + +\alias{getDateTimeParts} +\alias{getYear} +\alias{getYear.default} +\alias{getYear.Date} +\alias{getYear.POSIXct} +\alias{getYear.POSIXlt} + +\alias{getMonth} +\alias{getMonth.default} +\alias{getMonth.Date} +\alias{getMonth.POSIXct} +\alias{getMonth.POSIXlt} + +\alias{getDay} +\alias{getDay.default} +\alias{getDay.Date} +\alias{getDay.POSIXct} +\alias{getDay.POSIXlt} + +\alias{getHour} +\alias{getHour.default} + +\alias{getMin} +\alias{getMin.default} + +\alias{getSec} +\alias{getSec.default} + +\title{Get date/time parts from date and time objects} + +\description{get* functions provide an *experimental* approach for + extracting the date/time parts from objects of a date/time class. + They are designed to be intiutive and thus lowering the learning + curve for work with date and time classes in \R{}.} + +\usage{ + +getYear(x, format, \ldots) +getMonth(x, format, \ldots) +getDay(x, format, \ldots) +getHour(x, format, \ldots) +getMin(x, format, \ldots) +getSec(x, format, \ldots) + +} + + +\arguments{ + \item{x}{generic, date/time object} + \item{format}{character, format} + \item{\ldots}{arguments pased to other methods} +} + +\value{Character} + +\author{Gregor Gorjanc} + +\seealso{ + \code{\link{Date}}, + \code{\link{DateTimeClasses}}, + \code{\link{strptime}} +} + +\examples{ + +## --- Date class --- + +tmp <- Sys.Date() +tmp + +getYear(tmp) +getMonth(tmp) +getDay(tmp) + +## --- POSIXct class --- + +tmp <- as.POSIXct(tmp) + +getYear(tmp) +getMonth(tmp) +getDay(tmp) + +## --- POSIXlt class --- + +tmp <- as.POSIXlt(tmp) + +getYear(tmp) +getMonth(tmp) +getDay(tmp) + +} + +\keyword{manip} +\keyword{misc} + +%-------------------------------------------------------------------------- +% getDateTimeParts.Rd ends here \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gg...@us...> - 2008-12-31 13:28:05
|
Revision: 1309 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1309&view=rev Author: ggorjan Date: 2008-12-31 13:28:02 +0000 (Wed, 31 Dec 2008) Log Message: ----------- New function nPairs that gives the number of variable pairs in a data.frame or a matrix. Added Paths: ----------- trunk/gdata/R/nPairs.R trunk/gdata/inst/unitTests/runit.nPairs.R trunk/gdata/man/nPairs.Rd Added: trunk/gdata/R/nPairs.R =================================================================== --- trunk/gdata/R/nPairs.R (rev 0) +++ trunk/gdata/R/nPairs.R 2008-12-31 13:28:02 UTC (rev 1309) @@ -0,0 +1,49 @@ +### nPairs.R +###------------------------------------------------------------------------ +### What: Number of variable pairs - code +### $Id$ +### Time-stamp: <2008-12-30 18:29:58 ggorjan> +###------------------------------------------------------------------------ + +nPairs <- function(x, margin=FALSE, names=TRUE, abbrev=TRUE, ...) +{ + ## --- Setup --- + if(!is.data.frame(x) & !is.matrix(x)) stop("'x' must be a data.frame or a matrix") + k <- ncol(x) + if(!margin) { + ret <- matrix(nrow=k, ncol=k) + } else { + ret <- matrix(nrow=k, ncol=k + 1) + } + + ## --- Count --- + diag(ret)[1:k] <- apply(X=x, MARGIN=2, FUN=function(x) sum(!is.na(x))) + for(i in 1:k) { + for(j in i:k) { + ret[i, j] <- ret[j, i] <- sum(!is.na(x[, i]) & !is.na(x[, j])) + if(margin) { + if(i == 1) { + ret[i, (k + 1)] <- ret[1, 1] + } else { + ret[i, (k + 1)] <- sum(rowSums(!is.na(x[, c(1:i)])) == i) + } + } + } + } + + ## --- Names --- + if(names) { + tmp <- colnames(x) + if(abbrev) tmp <- as.character(abbreviate(tmp, ...)) + rownames(ret) <- tmp + if(margin) { + colnames(ret) <- c(tmp, "all") + } else { + colnames(ret) <- tmp + } + } + ret +} + +###------------------------------------------------------------------------ +### nPairs.R ends here Property changes on: trunk/gdata/R/nPairs.R ___________________________________________________________________ Added: svn:keywords + Added: trunk/gdata/inst/unitTests/runit.nPairs.R =================================================================== --- trunk/gdata/inst/unitTests/runit.nPairs.R (rev 0) +++ trunk/gdata/inst/unitTests/runit.nPairs.R 2008-12-31 13:28:02 UTC (rev 1309) @@ -0,0 +1,56 @@ +### runit.nPairs.R +###------------------------------------------------------------------------ +### What: Number of variable pairs - unit tests +### $Id$ +### Time-stamp: <2008-12-30 18:24:59 ggorjan> +###------------------------------------------------------------------------ + +### {{{ --- Test setup --- + +if(FALSE) { + library("RUnit") + library("gdata") +} + +### }}} +### {{{ --- nPairs --- + +test.nPairs <- function() +{ + ## 'x' must be a data.frame or a matrix + x <- rpois(100, lambda=10) + checkException(nPairs(x=x)) + checkException(nPairs(x=table(x))) + + test <- data.frame(V1=c(1, 2, 3, 4, 5), + V2=c(NA, 2, 3, 4, 5), + V3=c(1, NA, NA, NA, NA), + V4=c(1, 2, 3, NA, NA)) + testCheck <- matrix(as.integer(c(5, 4, 1, 3, + 4, 4, 0, 2, + 1, 0, 1, 1, + 3, 2, 1, 3)), + nrow=4, ncol=4, byrow=TRUE) + + testCheckNames <- testCheck + colnames(testCheckNames) <- rownames(testCheckNames) <- colnames(test) + + checkIdentical(nPairs(x=test), testCheckNames) + checkIdentical(nPairs(x=test, names=FALSE), testCheck) + checkIdentical(nPairs(x=as.matrix(test)), testCheckNames) + checkIdentical(nPairs(x=as.matrix(test), names=FALSE), testCheck) + + testCheck <- cbind(testCheckNames, as.integer(c(5, 4, 0, 0))) + colnames(testCheck) <- c(colnames(test), "all") + checkIdentical(nPairs(x=test, margin=TRUE), testCheck) +} + +### }}} +### {{{ Dear Emacs +### Local variables: +### folded-file: t +### end: +### }}} + +###------------------------------------------------------------------------ +### runit.nPairs.R ends here Property changes on: trunk/gdata/inst/unitTests/runit.nPairs.R ___________________________________________________________________ Added: svn:keywords + Added: trunk/gdata/man/nPairs.Rd =================================================================== --- trunk/gdata/man/nPairs.Rd (rev 0) +++ trunk/gdata/man/nPairs.Rd 2008-12-31 13:28:02 UTC (rev 1309) @@ -0,0 +1,73 @@ +% nPairs.Rd +%-------------------------------------------------------------------------- +% What: Number of variable pairs - help +% $Id$ +% Time-stamp: <2008-12-30 18:30:11 ggorjan> +%-------------------------------------------------------------------------- + +\name{nPairs} + +\alias{nPairs} + +\concept{pairs} + +\title{Number of variable pairs} + +\description{ + +\code{nPairs} counts the number of pairs between variables. + +} + +\usage{ +nPairs(x, margin=FALSE, names=TRUE, abbrev=TRUE, ...) +} + +\arguments{ + \item{x}{data.frame or a matrix} + \item{margin}{logical, calculate the cumulative number of \dQuote{pairs}} + \item{names}{logical, add row/col-names to the output} + \item{abbrev}{logical, abbreviate names} + \item{\ldots}{other arguments passed to \code{\link{abbreviate}}} +} + +\value{ + +Matrix of order \eqn{k}, where \eqn{k} is the number of columns in \code{x}. +Values in a matrix represent the number of pairs between columns/variables in +\code{x}. If \code{margin=TRUE}, the number of columns is \eqn{k+1} and the +last column represents the cumulative number of pairing all variables. + +} + +\author{Gregor Gorjanc} + +\seealso{\code{\link{abbreviate}}} + +\examples{ + +## Test data +test <- data.frame(V1=c(1, 2, 3, 4, 5), + V2=c(NA, 2, 3, 4, 5), + V3=c(1, NA, NA, NA, NA), + V4=c(1, 2, 3, NA, NA)) + +## Number of variable pairs +nPairs(x=test) + +## Without names +nPairs(x=test, names=FALSE) + +## Longer names +colnames(test) <- c("Variable1", "Variable2", "Variable3", "Variable4") +nPairs(x=test) + +## Margin +nPairs(x=test, margin=TRUE) + +} + +\keyword{misc} + +%-------------------------------------------------------------------------- +% nPairs.Rd ends here This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gg...@us...> - 2008-12-31 13:29:09
|
Revision: 1310 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1310&view=rev Author: ggorjan Date: 2008-12-31 13:29:03 +0000 (Wed, 31 Dec 2008) Log Message: ----------- New function wideByFactor that reshapes given dataset by a given factor - it creates a "multivariate" data.frame. Added Paths: ----------- trunk/gdata/R/wideByFactor.R trunk/gdata/inst/unitTests/runit.wideByFactor.R trunk/gdata/man/wideByFactor.Rd Added: trunk/gdata/R/wideByFactor.R =================================================================== --- trunk/gdata/R/wideByFactor.R (rev 0) +++ trunk/gdata/R/wideByFactor.R 2008-12-31 13:29:03 UTC (rev 1310) @@ -0,0 +1,40 @@ +### wideByFactor.R +###------------------------------------------------------------------------ +### What: Reshape by factor levels - code +### $Id$ +### Time-stamp: <2008-12-30 22:17:32 ggorjan> +###------------------------------------------------------------------------ + +wideByFactor <- function(x, factor, common, sort=TRUE, keepFactor=TRUE) +{ + ## --- Setup --- + if(!is.data.frame(x)) stop("'x' must be a data frame") + if(length(factor) != 1) stop("'factor' can be only of length one") + if(!is.factor(x[[factor]])) stop("column defined in 'factor' must be a factor") + if(sort) x <- x[order(x[[factor]]), ] + + ## --- Extend by factors levels --- + y <- x[common] + if(keepFactor) y[factor] <- x[factor] + levs <- levels(x[[factor]]) + + ## Remove common and factor from the list of column names + other <- names(x) + other <- other[!(other %in% common) & !(other %in% factor)] + + ## Add all other columns but as a set for each level of a factor + for(level in levs) { + for(col in other) { + ## add a column col + y[paste(col, level, sep=".")] <- x[col] + ## fill with NA for other levels than level + y[x[factor] != level, paste(col, level, sep=".")] <- NA + ## This filling migth be inefficient if there is large number + ## of levels, since there will be quite a lot of filling. + } + } + y +} + +###------------------------------------------------------------------------ +### wideByFactor.R ends here \ No newline at end of file Property changes on: trunk/gdata/R/wideByFactor.R ___________________________________________________________________ Added: svn:keywords + Added: trunk/gdata/inst/unitTests/runit.wideByFactor.R =================================================================== --- trunk/gdata/inst/unitTests/runit.wideByFactor.R (rev 0) +++ trunk/gdata/inst/unitTests/runit.wideByFactor.R 2008-12-31 13:29:03 UTC (rev 1310) @@ -0,0 +1,55 @@ +### runit.wideByFactor.R +###------------------------------------------------------------------------ +### What: Reshape by factor levels - unit tests +### $Id$ +### Time-stamp: <2008-12-30 11:58:50 ggorjan> +###------------------------------------------------------------------------ + +### {{{ --- Test setup --- + +if(FALSE) { + library("RUnit") + library("gdata") +} + +### }}} +### {{{ --- wideByFactor --- + +test.wideByFactor <- function() +{ + n <- 10 + f <- 2 + tmp <- data.frame(y1=(1:n)/2, + y2=(n:1)*2, + f1=factor(rep(letters[1:f], n/2)), + f2=factor(c(rep(c("M"), n/2), rep(c("F"), n/2))), + c1=1:n, + c2=2*(1:n)) + + ## 'x' must be a data.frame + checkException(wideByFactor(x=1:10)) + checkException(wideByFactor(x=matrix(1:10))) + ## 'factor' can be only of length one + checkException(wideByFactor(x=tmp, factor=c("f1", "f2"))) + ## column defined in 'factor' must be a factor + checkException(wideByFactor(x=tmp, factor="c1")) + + tmp2 <- wideByFactor(x=tmp, factor="f1", common=c("c1", "c2"), sort=FALSE) + checkEquals(tmp2[c("c1", "c2")], tmp[c("c1", "c2")]) + checkEquals(names(tmp2), c("c1", "c2", "f1", "y1.a", "y2.a", "f2.a", "y1.b", "y2.b", "f2.b")) + checkEquals(tmp2$y1.a, c(0.5, NA, 1.5, NA, 2.5, NA, 3.5, NA, 4.5, NA)) + checkEquals(tmp2$f2.a, factor(c("M", NA, "M", NA, "M", NA, "F", NA, "F", NA))) + tmp2 <- wideByFactor(x=tmp, factor="f1", common=c("c1", "c2"), sort=TRUE, keepFactor=FALSE) + checkEquals(tmp2$f2.a, factor(c("M", "M", "M", "F", "F", NA, NA, NA, NA, NA))) + checkEquals(names(tmp2), c("c1", "c2", "y1.a", "y2.a", "f2.a", "y1.b", "y2.b", "f2.b")) +} + +### }}} +### {{{ Dear Emacs +## Local variables: +## folded-file: t +## End: +### }}} + +###------------------------------------------------------------------------ +### runit.wideByFactor.R ends here Property changes on: trunk/gdata/inst/unitTests/runit.wideByFactor.R ___________________________________________________________________ Added: svn:keywords + Added: trunk/gdata/man/wideByFactor.Rd =================================================================== --- trunk/gdata/man/wideByFactor.Rd (rev 0) +++ trunk/gdata/man/wideByFactor.Rd 2008-12-31 13:29:03 UTC (rev 1310) @@ -0,0 +1,73 @@ +% wideByFactor.Rd +%-------------------------------------------------------------------------- +% What: Reshape by factor levels - help +% $Id$ +% Time-stamp: <2008-12-30 13:49:50 ggorjan> +%-------------------------------------------------------------------------- + +\name{wideByFactor} +\alias{wideByFactor} + +\title{Create multivariate data by a given factor} + +\description{ + +\code{wideByFactor} modifies data.frame in such a way that variables are +\dQuote{separated} into several columns by factor levels. + +} + +\usage{ + wideByFactor(x, factor, common, sort=TRUE, keepFactor=TRUE) +} + +\arguments{ + \item{x}{data frame} + \item{factor}{character, column name of a factor by which variables will + be divided} + \item{common}{character, column names of (common) columns that should not + be divided} + \item{sort}{logical, sort resulting data frame by factor levels} + \item{keepFactor}{logical, keep the \sQuote{factor} column} +} + +\details{ + +Given data frame is modified in such a way, that output represents a data frame +with \eqn{c + f + n * v} columns, where \eqn{c} is a number of common columns +for all levels of a factor, \eqn{f} is a factor column, \eqn{n} is a number of +levels in factor \eqn{f} and \eqn{v} is a number of variables that should be +divided for each level of a factor. Number of rows stays the same! +} + +\value{ + A data frame where divided variables have sort of \dQuote{diagonalized} structure +} + +\author{Gregor Gorjanc} + +\seealso{ + \code{\link[stats]{reshape}} in the \pkg{stats} package, + \code{\link[reshape]{melt}} and \code{\link[reshape]{cast}} in + the \pkg{reshape} package +} + +\examples{ +n <- 10 +f <- 2 +tmp <- data.frame(y1=rnorm(n=n), + y2=rnorm(n=n), + f1=factor(rep(letters[1:f], n/2)), + f2=factor(c(rep(c("M"), n/2), rep(c("F"), n/2))), + c1=1:n, + c2=2*(1:n)) + +wideByFactor(x=tmp, factor="f1", common=c("c1", "c2", "f2")) +wideByFactor(x=tmp, factor="f1", common=c("c1", "c2")) +} + +\keyword{manip} +\keyword{misc} + +%-------------------------------------------------------------------------- +% wideByFactor.Rd ends here \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gg...@us...> - 2008-12-31 13:30:10
|
Revision: 1311 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1311&view=rev Author: ggorjan Date: 2008-12-31 13:30:07 +0000 (Wed, 31 Dec 2008) Log Message: ----------- Enhanced function object.size that returns the size of multiple objects. There is also a handy print method that can print size of an object in "human readable" format when options(humanReadable=TRUE) or print(object.size(x), humanReadable=TRUE). Added Paths: ----------- trunk/gdata/R/object.size.R trunk/gdata/man/humanReadable.Rd trunk/gdata/man/object.size.Rd Added: trunk/gdata/R/object.size.R =================================================================== --- trunk/gdata/R/object.size.R (rev 0) +++ trunk/gdata/R/object.size.R 2008-12-31 13:30:07 UTC (rev 1311) @@ -0,0 +1,92 @@ +### object.size.R +###------------------------------------------------------------------------ +### What: Print object size in human readable format - code +### $Id$ +### Time-stamp: <2008-12-30 08:05:43 ggorjan> +###------------------------------------------------------------------------ + +object.size <- function(...) +{ + structure(sapply(list(...), function(x) .Internal(object.size(x))), + class=c("object_size", "numeric")) +} + +print.object_size <- function(x, quote=FALSE, humanReadable, ...) +{ + xOrig <- x + if(missing(humanReadable)) { + opt <- getOption("humanReadable") + humanReadable <- ifelse(!is.null(opt), opt, FALSE) + } + if(humanReadable) { + print(humanReadable(x), quote=quote, ...) + } else { + class(x) <- "numeric" + NextMethod() + } + invisible(xOrig) +} + +is.object_size <- function(x) inherits(x, what="object_size") + +as.object_size <- function(x) +{ + if(!is.numeric(x)) stop("'x' must be numeric/integer") + class(x) <- c("object_size", "numeric") + x +} + +c.object_size <- function(..., recursive=FALSE) +{ + x <- NextMethod() + if(is.numeric(x)) class(x) <- c("object_size", "numeric") + x +} + +humanReadable <- function(x, standard="SI", digits=1, width=3, sep=" ") +{ + ## --- Setup --- + + if(any(x < 0)) stop("'x' must be positive") + if(standard == "SI") { + suffix <- c("B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB") + base <- 1000 + } else { + suffix <- c("B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB") + base <- 1024 + } + + ## --- Apply --- + + .applyHuman <- function(x, base, suffix, digits, width, sep) + { + ## Which suffix should we use? + n <- length(suffix) + for(i in 1:n) { + if(x >= base) { + if(i < n) x <- x / base + } else { + break + } + } + ## Formatting + if(is.null(width)) { ## the same formatting for all + x <- format(round(x=x, digits=digits), nsmall=digits) + } else { ## similar to ls, du, and df + lenX <- nchar(x) + if(lenX > width) { + digitsMy <- width - (lenX - (lenX - (nchar(round(x)) + 1))) + digits <- ifelse(digitsMy > digits, digits, digitsMy) + } + if(i == 1) digits <- 0 + x <- round(x, digits=digits) + } + paste(x, suffix[i], sep=sep) + } + + sapply(X=x, FUN=".applyHuman", base=base, suffix=suffix, digits=digits, + width=width, sep=sep) +} + +###------------------------------------------------------------------------ +### object.size.R ends here Property changes on: trunk/gdata/R/object.size.R ___________________________________________________________________ Added: svn:keywords + Added: trunk/gdata/man/humanReadable.Rd =================================================================== --- trunk/gdata/man/humanReadable.Rd (rev 0) +++ trunk/gdata/man/humanReadable.Rd 2008-12-31 13:30:07 UTC (rev 1311) @@ -0,0 +1,131 @@ +% humanReadable.Rd +%-------------------------------------------------------------------------- +% What: Print byte size in human readable format man page +% $Id$ +% Time-stamp: <2008-12-30 13:26:35 ggorjan> +%-------------------------------------------------------------------------- + +\name{humanReadable} + +\alias{humanReadable} + +\title{Print byte size in human readable format} + +\description{ + +\code{humanReadable} converts byte size in human readable format such as +kB, MB, GB, etc. + +} + +\usage{ + +humanReadable(x, standard="SI", digits=1, width=3, sep=" ") + +} + +\arguments{ + \item{x}{integer, byte size} + \item{standard}{character, "SI" for powers of 1000 or anything else for + powers of 1024, see details} + \item{digits}{integer, number of digits after decimal point} + \item{width}{integer, width of number string} + \item{sep}{character, separator between number and unit} +} + +\details{ + +Basic unit used to store information in computers is a bit. Bits are +represented as zeroes and ones - binary number system. Although, the binary +number system is not the same as the decimal number system, decimal prefixes +for binary multiples such as kilo and mega are often used. In the decimal system +kilo represent 1000, which is close to \eqn{1024 = 2^{10}} in the binary system. +This sometimes causes problems as it is not clear which powers (2 or 10) are used +in a notation like 1 kB. To overcome this problem International Electrotechnical +Commission (IEC) has provided the following solution to this problem: + +\tabular{lrcll}{ +Name \tab System \tab Symbol \tab Size \tab Conversion \cr +byte \tab binary \tab B \tab \eqn{2^3} \tab 8 bits \cr +kilobyte \tab decimal \tab kB \tab \eqn{10^3} \tab 1000 bytes \cr +kibibyte \tab binary \tab KiB \tab \eqn{2^{10}} \tab 1024 bytes \cr +megabyte \tab decimal \tab MB \tab \eqn{(10^3)^2} \tab 1000 kilobytes\cr +mebibyte \tab binary \tab MiB \tab \eqn{(2^{10})^2} \tab 1024 kibibytes\cr +gigabyte \tab decimal \tab GB \tab \eqn{(10^3)^3} \tab 1000 megabytes\cr +gibibyte \tab binary \tab GiB \tab \eqn{(2^{10})^3} \tab 1024 mebibytes\cr +terabyte \tab decimal \tab TB \tab \eqn{(10^3)^4} \tab 1000 gigabytes\cr +tebibyte \tab binary \tab TiB \tab \eqn{(2^{10})^4} \tab 1024 gibibytes\cr +petabyte \tab decimal \tab PB \tab \eqn{(10^3)^5} \tab 1000 terabytes\cr +pebibyte \tab binary \tab PiB \tab \eqn{(2^{10})^5} \tab 1024 tebibytes\cr +exabyte \tab decimal \tab EB \tab \eqn{(10^3)^6} \tab 1000 petabytes\cr +exbibyte \tab binary \tab EiB \tab \eqn{(2^{10})^6} \tab 1024 pebibytes\cr +zettabyte \tab decimal \tab ZB \tab \eqn{(10^3)^7} \tab 1000 exabytes\cr +zebibyte \tab binary \tab ZiB \tab \eqn{(2^{10})^7} \tab 1024 exbibytes\cr +yottabyte \tab decimal \tab YB \tab \eqn{(10^3)^8} \tab 1000 zettabytes\cr +yebibyte \tab binary \tab YiB \tab \eqn{(2^{10})^8} \tab 1024 zebibytes\cr +} + +where Zi and Yi are GNU extensions to IEC. To get the output in the decimal +system (powers of 1000) use \code{standard="SI"}. Otherwise IEC standard +(powers of 1024) is used. + +For printout both \code{digits} and \code{width} can be specified. If +\code{width} is \code{NULL}, all values have given number of digits. If +\code{width} is not \code{NULL}, output is rounded to a given width and +formated similar to human readable format of \code{ls}, \code{df} or +\code{du} shell commands. + +} + +\references{ + +Wikipedia: +\url{http://en.wikipedia.org/wiki/Byte} +\url{http://en.wikipedia.org/wiki/SI_prefix} +\url{http://en.wikipedia.org/wiki/Binary_prefix} + +GNU manual for coreutils: +\url{http://www.gnu.org/software/coreutils/manual/html_node/Block-size.html#Block-size} + +} + +\value{ + +Byte size in human readable format as character with proper unit symbols +added at the end of the string. + +} + +\author{Ales Korosec and Gregor Gorjanc} + +\seealso{ + \code{\link{object.size}}, \code{\link[gdata]{ll}} +} + +\examples{ + +baseSI <- 10 +powerSI <- seq(from=3, to=27, by=3) +SI0 <- (baseSI)^powerSI +k <- length(SI0) - 1 +SI1 <- SI0 - SI0 / c(2, runif(n=k, min=1.01, max=5.99)) +SI2 <- SI0 + SI0 / c(2, runif(n=k, min=1.01, max=5.99)) + +baseIEC <- 2 +powerIEC <- seq(from=10, to=90, by=10) +IEC0 <- (baseIEC)^powerIEC +IEC1 <- IEC0 - IEC0 / c(2, runif(n=k, min=1.01, max=5.99)) +IEC2 <- IEC0 + IEC0 / c(2, runif(n=k, min=1.01, max=5.99)) + +cbind(humanReadable(x=SI1, width=NULL, digits=3), + humanReadable(x=SI0, width=NULL, digits=2), + humanReadable(x=SI2, width=NULL, digits=1), + humanReadable(x=IEC1, standard="IEC", width=7, digits=3), + humanReadable(x=IEC0, standard="IEC", width=7, digits=2), + humanReadable(x=IEC2, standard="IEC", width=7, digits=1)) +} + +\keyword{misc} + +%-------------------------------------------------------------------------- +% humanReadable.Rd ends here Added: trunk/gdata/man/object.size.Rd =================================================================== --- trunk/gdata/man/object.size.Rd (rev 0) +++ trunk/gdata/man/object.size.Rd 2008-12-31 13:30:07 UTC (rev 1311) @@ -0,0 +1,85 @@ +% File src/library/utils/man/object.size.Rd +% Part of the R package, http://www.R-project.org +% Copyright 1995-2007 R Core Development Team +% Distributed under GPL 2 or later + +\name{object.size} +\alias{object.size} +\alias{print.object_size} +\alias{c.object_size} +\alias{as.object_size} +\alias{is.object_size} + +\title{Report the Space Allocated for an Object} +\description{ + Provides an estimate of the memory that is being used to store an \R object. +} +\usage{ +object.size(\dots) + +\method{print}{object_size}(x, quote=FALSE, humanReadable, \dots) +} +\arguments{ + \item{\dots}{\code{object.size}: \R objects; \code{print}; arguments + to be passed to or from other methods.} + \item{x}{output from \code{object.size}} + \item{quote}{logical, indicating whether or not the result should be + printed with surrounding quotes.} + \item{humanReadable}{logical, use the \dQuote{human readable} format.} +} +\details{ + + This is a modified copy from the utils package in R as fo 2008-12-15. + + Exactly which parts of the memory allocation should be attributed to + which object is not clear-cut. This function merely provides a rough + indication: it should be reasonably accurate for atomic vectors, but + does not detect if elements of a list are shared, for example. + (Sharing amongst elements of a character vector is taken into account, + but not that between character vectors in a single object.) + + The calculation is of the size of the object, and excludes the space + needed to store its name in the symbol table. + + Associated space (e.g. the environment of a function and what the + pointer in a \code{EXTPTRSXP} points to) is not included in the + calculation. + + Object sizes are larger on 64-bit platforms than 32-bit ones, but will + very likely be the same on different platforms with the same word + length and pointer size. + + % Modificitaion start + Class of returned object is \code{c("byte", "numeric")} with + appropriate \code{print} and \code{c} methods. + + By default \code{object.size} outputs size in bytes, but human + readable format similar to \code{ls}, \code{df} or \code{du} shell + commands can be invoked with \code{options(humanReadable=TRUE)}. + % Modificitaion end + +} +\value{ + An object of class \code{"object.size"} with a length-one double value, + an estimate of the memory allocation attributable to the object in bytes. +} +\seealso{ + \code{\link{Memory-limits}} for the design limitations on object size. + \code{\link{humanReadable}} for human readable format. +} + +\examples{ +object.size(letters) +object.size(ls) +## find the 10 largest objects in the base package +z <- sapply(ls("package:base"), function(x) + object.size(get(x, envir = baseenv()))) +(tmp <- as.matrix(rev(sort(z))[1:10])) + +as.object_size(14567567) +options(humanReadable=TRUE) +(z <- object.size(letters, c(letters, letters), rep(letters, 100), rep(letters, 10000))) +is.object_size(z) +as.object_size(14567567) +} +\keyword{utilities} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gg...@us...> - 2008-12-31 13:30:54
|
Revision: 1312 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1312&view=rev Author: ggorjan Date: 2008-12-31 13:30:45 +0000 (Wed, 31 Dec 2008) Log Message: ----------- Documenting changes and exporting the functions. Modified Paths: -------------- trunk/gdata/NAMESPACE trunk/gdata/inst/NEWS Modified: trunk/gdata/NAMESPACE =================================================================== --- trunk/gdata/NAMESPACE 2008-12-31 13:30:07 UTC (rev 1311) +++ trunk/gdata/NAMESPACE 2008-12-31 13:30:45 UTC (rev 1312) @@ -2,6 +2,7 @@ export( Args, aggregate.table, + bindData, cbindX, combine, ConvertMedUnits, @@ -17,31 +18,35 @@ "lowerTriangle<-", matchcols, nobs, + nPairs, read.xls, rename.vars, remove.vars, reorder.factor, resample, trim, - trimSum, + trimSum, unmatrix, upperTriangle, "upperTriangle<-", + wideByFactor, write.fwf, xls2csv, + ## Object size stuff + object.size, as.object_size, is.object_size, humanReadable, + + ## getDateTime stuff + getYear, getMonth, getDay, getHour, getMin, getSec, + ## mapLevels stuff - mapLevels, - as.levelsMap, - as.listLevelsMap, - is.levelsMap, - is.listLevelsMap, - "mapLevels<-", + mapLevels, as.levelsMap, as.listLevelsMap, is.levelsMap, is.listLevelsMap, "mapLevels<-", ## unknown stuff - isUnknown, - unknownToNA, - NAToUnknown + isUnknown, unknownToNA, NAToUnknown, + + ## Unit testing + .runRUnitTestsGdata ) importFrom(stats, reorder) @@ -55,6 +60,28 @@ S3method(drop.levels, list) S3method(drop.levels, data.frame) +## getDateTime stuff +S3method(getYear, default) +S3method(getYear, Date) +S3method(getYear, POSIXct) +S3method(getYear, POSIXlt) + +S3method(getMonth, default) +S3method(getMonth, Date) +S3method(getMonth, POSIXct) +S3method(getMonth, POSIXlt) + +S3method(getDay, default) +S3method(getDay, Date) +S3method(getDay, POSIXct) +S3method(getDay, POSIXlt) + +S3method(getHour, default) + +S3method(getMin, default) + +S3method(getSec, default) + ## mapLevels stuff S3method(mapLevels, default) S3method(mapLevels, character) @@ -83,6 +110,10 @@ S3method(nobs, default) S3method(nobs, lm) +## Object size stuff +S3method(print, object_size) +S3method(c, object_size) + ## unknown stuff S3method(isUnknown, default) S3method(isUnknown, POSIXlt) Modified: trunk/gdata/inst/NEWS =================================================================== --- trunk/gdata/inst/NEWS 2008-12-31 13:30:07 UTC (rev 1311) +++ trunk/gdata/inst/NEWS 2008-12-31 13:30:45 UTC (rev 1312) @@ -1,12 +1,31 @@ -CHANGES IN 2.5.0 (2008-??-??) +CHANGES IN 2.5.0 (2009-??-??) ----------------------------- -- New function trimSum that sums trimmed values +- New function .runRUnitTestsGdata that enables run of all RUnit tests during + the R CMD check as well as directly from within R. +- Enhanced function object.size that returns the size of multiple objects. There + is also a handy print method that can print size of an object in "human readable" + format when options(humanReadable=TRUE) or print(x, humanReadable=TRUE). + +- New function bindData that binds two data frames into a multivariate data frame + in a different way than merge. + +- New function wideByFactor that reshapes given dataset by a given factor - + it creates a "multivariate" data.frame. + +- New functions getYear, getMonth, getDay, getHour, getMin, and getSec for + extracting the date/time parts from objects of a date/time class. + +- New function nPairs that gives the number of variable pairs in a data.frame + or a matrix. + +- New function trimSum that sums trimmed values. + - New function cbindX that can bind objects with different number of rows. -- write.fwf gains width argument. Unknown values can increase or decrease - the width of the columns. Additional tests and documentation fixes. +- write.fwf gains the width argument. The value for unknown can increase or + decrease the width of the columns. Additional tests and documentation fixes. CHANGES IN 2.4.2 (2008-05-11) ----------------------------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2009-07-16 02:49:24
|
Revision: 1342 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1342&view=rev Author: warnes Date: 2009-07-16 02:49:11 +0000 (Thu, 16 Jul 2009) Log Message: ----------- Add support for using tab for field separator during translation from xls format in read.xls Modified Paths: -------------- trunk/gdata/NAMESPACE trunk/gdata/R/read.xls.R trunk/gdata/man/read.xls.Rd Added Paths: ----------- trunk/gdata/inst/perl/xls2tab.pl Modified: trunk/gdata/NAMESPACE =================================================================== --- trunk/gdata/NAMESPACE 2009-05-09 05:45:13 UTC (rev 1341) +++ trunk/gdata/NAMESPACE 2009-07-16 02:49:11 UTC (rev 1342) @@ -32,6 +32,8 @@ wideByFactor, write.fwf, xls2csv, + xls2tab, + xls2sep, ## Object size stuff object.size, as.object_size, is.object_size, humanReadable, Modified: trunk/gdata/R/read.xls.R =================================================================== --- trunk/gdata/R/read.xls.R 2009-05-09 05:45:13 UTC (rev 1341) +++ trunk/gdata/R/read.xls.R 2009-07-16 02:49:11 UTC (rev 1342) @@ -4,126 +4,170 @@ dQuote.ascii <- function(x) paste('"',x,'"',sep='') -xls2csv <- function(xls, sheet = 1, verbose=FALSE, ..., perl="perl") - { +xls2csv <- function(xls, sheet=1, verbose=FALSE, ..., perl="perl") + xls2sep(xls=xls, sheet=sheet, verbose=verbose, ..., method="csv", + perl="perl") +xls2tab <- function(xls, sheet=1, verbose=FALSE, ..., perl="perl") + xls2sep(xls=xls, sheet=sheet, verbose=verbose, ..., method="tab", + perl="perl") - ### - # directories - package.dir <- .path.package('gdata') - perl.dir <- file.path(package.dir,'perl') - # - ### +xls2sep <- function(xls, sheet = 1, verbose=FALSE, ..., + method=c("csv","tab"), perl="perl") + { + + method <- match.arg(method) + + ## + ## directories + package.dir <- .path.package('gdata') + perl.dir <- file.path(package.dir,'perl') + ## - ### - # files + ## + ## files + tf <- NULL + if (substring(xls, 1, 7) == "http://") { + tf <- paste(tempfile(), "xls", sep = ".") + if(verbose) + cat("Downloading", + dQuote.ascii(xls), " to ", + dQuote.ascii(tf), "...\n") + else + cat("Downloading...\n") + download.file(xls, tf, mode = "wb") + cat("Done.\n") + xls <- tf + } - tf <- NULL - if (substring(xls, 1, 7) == "http://") { - tf <- paste(tempfile(), "xls", sep = ".") - if(verbose) - cat("Downloading", - dQuote.ascii(xls), " to ", - dQuote.ascii(tf), "...\n") - else - cat("Downloading...\n") - download.file(xls, tf, mode = "wb") - cat("Done.\n") - xls <- tf - } + if(file.access(xls, 4)!=0) + stop("Unable to read xls file '", xls, "'." ) - if(file.access(xls, 4)!=0) - stop("Unable to read xls file '", xls, "'." ) + if(method=="csv") + { + script <- file.path(perl.dir,'xls2csv.pl') + targetFile <- paste(tempfile(), "csv", sep = ".") + } + else if(method=="tab") + { + script <- file.path(perl.dir,'xls2tab.pl') + targetFile <- paste(tempfile(), "tab", sep = ".") + } + else + { + stop("Unknown method", method) + } + + ## + ## - xls2csv <- file.path(perl.dir,'xls2csv.pl') - csv <- paste(tempfile(), "csv", sep = ".") - # - ### + ## + ## execution command + cmd <- paste(perl, script, dQuote.ascii(xls), dQuote.ascii(targetFile), + sheet, sep=" ") + ## + ## - ### - # execution command - cmd <- paste(perl, xls2csv, dQuote.ascii(xls), dQuote.ascii(csv), - sheet, sep=" ") - # - ### - if(verbose) { cat("\n") cat("Converting xls file\n") cat(" ", dQuote.ascii(xls), "\n") - cat("to csv file \n") - cat(" ", dQuote.ascii(csv), "\n") + cat("to", method, " file \n") + cat(" ", dQuote.ascii(targetFile), "\n") cat("... \n\n") } - else - cat("Converting xls file to csv file... ") + else + cat("Converting xls file to", method, "file... ") - ### - # do the translation - if(verbose) cat("Executing ", cmd, "... \n\n") - # - results <- system(cmd, intern=!verbose) - # - if (verbose) cat("Done.\n\n") - # - ### + ## + ## do the translation + if(verbose) cat("Executing ", cmd, "... \n\n") + # + results <- system(cmd, intern=!verbose) + # + if (verbose) cat("Done.\n\n") + # + ## - if(file.access(csv, 4)!=0) - stop("Unable to read translated csv file '", csv, "'." ) + if(file.access(targetFile, 4)!=0) + stop("Unable to read translated", method, "file '", targetFile, "'." ) - cat("Done.\n") + cat("Done.\n") - # prepare for cleanup now, in case of error reading file - file(csv) -} + ## prepare for cleanup now, in case of error reading file + file(targetFile) + } -read.xls <- function(xls, sheet = 1, verbose=FALSE, pattern, ..., perl="perl") { - con <- tfn <- NULL - on.exit({ - if (inherits(con, "connection") && isOpen(con)) close(con) - if (file.exists(tfn)) file.remove(tfn) - }) +read.xls <- function(xls, sheet = 1, verbose=FALSE, pattern, ..., + method=c("csv","tab"), perl="perl") +{ + con <- tfn <- NULL + on.exit({ + if (inherits(con, "connection") && isOpen(con)) close(con) + if (file.exists(tfn)) file.remove(tfn) + }) - ## expand file path, translating ~ to user's home directory, etc. - xls <- path.expand(xls) + method <- match.arg(method) + + ## expand file path, translating ~ to user's home directory, etc. + xls <- path.expand(xls) - ## translate from xls to csv format (returns csv file name) - con <- xls2csv(xls, sheet, verbose=verbose, ..., perl = perl) + ## 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) - ## load the csv file - open(con) - tfn <- summary(con)$description - if (missing(pattern)) - { - if(verbose) - cat("Reading csv file ", dQuote.ascii(tfn), "...\n") - else - cat("Reading csv file... ") - retval <- read.csv(con, ...) - cat("Done.\n") - } - else { - cat("Searching for lines containing pattern ", pattern, "... ") - idx <- grep(pattern, readLines(con)) - if (length(idx) == 0) { - warning("pattern not found") - return(NULL) - } - cat("Done.\n") - - seek(con, 0) + ## load the csv file + open(con) + tfn <- summary(con)$description + if (missing(pattern)) + { + if(verbose) + cat("Reading", method, "file ", dQuote.ascii(tfn), "...\n") + else + cat("Reading", method, "file... ") + + if(method=="csv") + retval <- read.csv(con, ...) + else if (method=="tab") + retval <- read.delim(con, ...) + else + stop("Unknown method", method) + + cat("Done.\n") + } + else { + cat("Searching for lines containing pattern ", pattern, "... ") + idx <- grep(pattern, readLines(con)) + if (length(idx) == 0) { + warning("pattern not found") + return(NULL) + } + cat("Done.\n") + + seek(con, 0) - if(verbose) - cat("Reading csv file ", dQuote.ascii(tfn), "...\n") - else - cat("Reading csv file... ") - retval <- read.csv(con, skip = idx[1]-1, ...) - cat("Done.\n") - } - retval + if(verbose) + cat("Reading", method, "file ", dQuote.ascii(tfn), "...\n") + else + cat("Reading", method, "file... ") + + if(method=="csv") + retval <- read.csv(con, skip = idx[1]-1, ...) + else if (method=="tab") + retval <- read.delim(con, skip = idx[1]-1, ...) + else + stop("Unknown method", method) + + cat("Done.\n") + } + retval } Copied: trunk/gdata/inst/perl/xls2tab.pl (from rev 1341, trunk/gdata/inst/perl/xls2csv.pl) =================================================================== --- trunk/gdata/inst/perl/xls2tab.pl (rev 0) +++ trunk/gdata/inst/perl/xls2tab.pl 2009-07-16 02:49:11 UTC (rev 1342) @@ -0,0 +1,166 @@ +#!/bin/env perl + +BEGIN { +use File::Basename; +unshift(@INC, dirname $0); +} + +use strict; +use Spreadsheet::ParseExcel; + +# declare some varibles local +my($row, $col, $sheet, $cell, $usage, $basename, $sheetnumber, $filename); + +## +## Usage information +## +$usage = <<EOF; + +xls2tab.pl <excel file> [<output file>] [<worksheet number>] + +Translate the Microsoft Excel spreadsheet file contained in +<excel file> into tab separated value format (TAB) and store +in <output file>. + +If <output file> is not specified, the output file will have the +same name as the input file with '.xls' or '.XLS' (if any) +removed and '.tab' appended. + +If no worksheet number is given, each worksheet will be written to +a separate file with the name '<output file>_<worksheet name>.tab'. + +EOF + +## +## parse arguments +## + +if(!defined($ARGV[0])) + { + print $usage; + exit 1; + } + +$basename = $ARGV[1]; +$basename =~ s/.tab//; +if ($basename eq "") + { + my @path; + @path = split(/[\/\\]/, $ARGV[0]); # split on file separator + $basename = $path[$#path]; + $basename =~ s/.xls//i; + } + +if(defined($ARGV[2]) ) + { + $sheetnumber = $ARGV[2]; + die "Sheetnumber must be an integer larger than 0." if $sheetnumber < 1; + } + +## +## open spreadsheet +## + +my $oExcel = new Spreadsheet::ParseExcel; + +print "Loading $ARGV[0] ...\n"; + +open(FH, "<$ARGV[0]") or die "Unable to open file '$ARGV[0]'.\n"; +close(FH); + +my $oBook = $oExcel->Parse($ARGV[0]); + +print "\n"; +print "Orignal Filename :", $oBook->{File} , "\n"; +print "Number of Sheets :", $oBook->{SheetCount} , "\n"; +print "Author :", $oBook->{Author} , "\n"; +print "\n"; + +my @sheetlist = (@{$oBook->{Worksheet}}); +if (defined($sheetnumber)) + { + @sheetlist=($sheetlist[$sheetnumber-1]); + } + +## +## iterate across each worksheet, writing out a separat tab file +## + +my $i=0; +foreach my $sheet (@sheetlist) +{ + $i++; + + my $sheetname = $sheet->{Name}; + if(defined($sheetnumber)) + { + $filename = "${basename}.tab"; + } + else + { + $filename = "${basename}_${sheetname}.tab"; + } + + print "Writing Sheet number $i ('$sheetname') to file '$filename'\n"; + + open(OutFile,">$filename"); + + my $cumulativeBlankLines=0; + + my $minrow = $sheet->{MinRow}; + my $maxrow = $sheet->{MaxRow}; + my $mincol = $sheet->{MinCol}; + my $maxcol = $sheet->{MaxCol}; + + print "Minrow=$minrow Maxrow=$maxrow Mincol=$mincol Maxcol=$maxcol\n"; + + for(my $row = $minrow; $row <= $maxrow; $row++) + { + my $outputLine = ""; + + for(my $col = $mincol; $col <= $maxcol; $col++) + { + my $cell = $sheet->{Cells}[$row][$col]; + if( defined($cell) ) + { + $_=$cell->Value; #{Val}; + + # convert '#NUM!' strings to missing (empty) values + s/#NUM!//; + + # escape double-quote characters in the data since + # they are used as field delimiters + s/\"/\\\"/g; + } + else + { + $_ = ''; + } + + $outputLine .= "\"" . $_ . "\"" if(length($_)>0); + + # separate cells with tabs + $outputLine .= "\t" if( $col != $maxcol) ; + + } + + #$outputLine =~ s/[\t ]+$//g; ## strip off trailing blanks and tabs + + # skip blank/empty lines + if( $outputLine =~ /^[\t ]*$/ ) + { + $cumulativeBlankLines++ + } + else + { + print OutFile "$outputLine \n" + } + } + + close OutFile; + + print " (Ignored $cumulativeBlankLines blank lines.)\n" + if ($cumulativeBlankLines); + print "\n"; +} + Property changes on: trunk/gdata/inst/perl/xls2tab.pl ___________________________________________________________________ Added: svn:executable + * Added: svn:keywords + Author Date Id Revision Added: svn:mergeinfo + Added: svn:eol-style + native Modified: trunk/gdata/man/read.xls.Rd =================================================================== --- trunk/gdata/man/read.xls.Rd 2009-05-09 05:45:13 UTC (rev 1341) +++ trunk/gdata/man/read.xls.Rd 2009-07-16 02:49:11 UTC (rev 1342) @@ -1,41 +1,53 @@ \name{read.xls} \alias{read.xls} \alias{xls2csv} +\alias{xls2tab} +\alias{xls2sep} \title{Read Excel files} \description{Reads a Microsoft Excel file into a data frame} \usage{ -read.xls(xls, sheet=1, verbose=FALSE, pattern, ..., perl="perl") +read.xls(xls, sheet=1, verbose=FALSE, pattern, ..., + method=c("csv","tab"), perl="perl") + xls2csv(xls, sheet=1, verbose=FALSE, ..., perl="perl") +xls2tab(xls, sheet=1, verbose=FALSE, ..., perl="perl") +xls2sep(xls, sheet=1, verbose=FALSE, ..., method=c("csv","tab"), + perl="perl") } \arguments{ - \item{xls}{name of the Microsoft Excel file. If on internet it - should begin with code{"http://"}.} - \item{sheet}{number of sheet within the Excel file from which data are - to be read} + \item{xls}{path to the Microsoft Excel file. To access a file on the + internet, start the path with "http://".} + \item{sheet}{number of the sheet within the Excel file from which data + are to be read} \item{verbose}{logical flag indicating whether details should be printed as the file is processed.} \item{pattern}{if specified, them skip all lines before the first - containing this string} + containing this string} \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{...}{additional arguments to read.table. The defaults of read.csv are used.} } \value{ - \code{"read.xls"} returns a data frame. \code{"xls2csv"} returns a - connection to a temporary file in csv format. + \code{"read.xls"} returns a data frame. + + \code{"xls2sep"} returns a temporary file in the specified format. + \code{"xls2csv"} and \code{"xls2tab"} are simply wrappers for + \code{"xls2sep"} specifying method as "csv" or "tab", respectively. } \details{ This function works translating the named Microsoft Excel file into a - temporary .csv file, using Greg Warnes' xls2csv Perl script (installed - as part of the gregmisc package). + temporary .csv or .tab file, using the xls2csv or xls2tab + Perl script installed as part of this (gdata) package. Caution: In the conversion to csv, strings will be quoted. This can be problem if you are trying to use the \code{comment.char} option of \code{read.table} since the first character of all lines (including comment lines) will be "\"" after conversion. - Caution: With \code{"xls2csv"} it is the responsibility of the user - to close and delete the file after using it. + Caution: If you call \code{"xls2csv"} directly, is your responsibility + to close and delete the file after using it. } \references{http://www.analytics.washington.edu/statcomp/downloads/xls2csv} \note{ Either a working version of Perl must be present in the executable @@ -48,9 +60,22 @@ xlsfile <- file.path(.path.package('gdata'),'xls','iris.xls') xlsfile - iris <- read.xls(xlsfile) + iris <- read.xls(xlsfile) # defaults to csv format + iris <- read.xls(xlsfile,method="csv") # specify csv format + iris <- read.xls(xlsfile,method="tab") # specify tab format + head(iris) # look at the top few rows + \dontshow{ + iris.1 <- read.xls(xlsfile) # defaults to csv format + iris.2 <- read.xls(xlsfile,method="csv") # specify csv format + iris.3 <- read.xls(xlsfile,method="tab") # specify tab format + + stopifnot(all.equal(iris.1, iris.2)) + stopifnot(all.equal(iris.1, iris.3)) + } + + \dontrun{ # Example specifying exact Perl path for default MS-Windows install of # ActiveState perl This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2009-07-16 02:55:32
|
Revision: 1345 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1345&view=rev Author: warnes Date: 2009-07-16 02:55:27 +0000 (Thu, 16 Jul 2009) Log Message: ----------- Correct Greg's email address Modified Paths: -------------- trunk/gdata/inst/doc/gregmisc.tex trunk/gdata/inst/doc/mapLevels.pdf trunk/gdata/inst/doc/unknown.pdf 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/rename.vars.Rd trunk/gdata/man/reorder.Rd trunk/gdata/man/trim.Rd trunk/gdata/man/unmatrix.Rd trunk/gdata/man/upperTriangle.Rd Modified: trunk/gdata/inst/doc/gregmisc.tex =================================================================== --- trunk/gdata/inst/doc/gregmisc.tex 2009-07-16 02:52:07 UTC (rev 1344) +++ trunk/gdata/inst/doc/gregmisc.tex 2009-07-16 02:55:27 UTC (rev 1345) @@ -95,8 +95,8 @@ \address{Gregory R. Warnes \\ - Pfizer Global Research and Development \\ - \emph{wa...@bs...} } %%!!!%% + Random Technologies LLC. \\ + \emph{gr...@ra...} } %%!!!%% \end{multicols} %%!!!%% Modified: trunk/gdata/inst/doc/mapLevels.pdf =================================================================== (Binary files differ) Modified: trunk/gdata/inst/doc/unknown.pdf =================================================================== (Binary files differ) Modified: trunk/gdata/man/ConvertMedUnits.Rd =================================================================== --- trunk/gdata/man/ConvertMedUnits.Rd 2009-07-16 02:52:07 UTC (rev 1344) +++ trunk/gdata/man/ConvertMedUnits.Rd 2009-07-16 02:55:27 UTC (rev 1345) @@ -46,7 +46,7 @@ \references{ \url{http://www.globalrph.com/conv_si.htm} } -\author{ Gregory R. Warnes \email{wa...@bs...} } +\author{ Gregory R. Warnes \email{gr...@ra...} } \examples{ data(MedUnits) Modified: trunk/gdata/man/aggregate.table.Rd =================================================================== --- trunk/gdata/man/aggregate.table.Rd 2009-07-16 02:52:07 UTC (rev 1344) +++ trunk/gdata/man/aggregate.table.Rd 2009-07-16 02:55:27 UTC (rev 1345) @@ -49,7 +49,7 @@ Returns a matrix with one element for each combination of \code{by1} and \code{by2}. } -\author{ Gregory R. Warnes \email{wa...@bs...}} +\author{ Gregory R. Warnes \email{gr...@ra...}} \seealso{ \code{\link{aggregate}}, \code{\link{tapply}}, \code{\link{interleave}} } Modified: trunk/gdata/man/combine.Rd =================================================================== --- trunk/gdata/man/combine.Rd 2009-07-16 02:52:07 UTC (rev 1344) +++ trunk/gdata/man/combine.Rd 2009-07-16 02:55:27 UTC (rev 1345) @@ -59,7 +59,7 @@ % ... % } %\references{ ~put references to the literature/web site here ~ } -\author{Gregory R. Warnes \email{wa...@bs...}} +\author{Gregory R. Warnes \email{gr...@ra...}} %\note{ ~~further notes~~ } \seealso{ \code{\link{rbind}}, \code{\link{merge}}} Modified: trunk/gdata/man/interleave.Rd =================================================================== --- trunk/gdata/man/interleave.Rd 2009-07-16 02:52:07 UTC (rev 1344) +++ trunk/gdata/man/interleave.Rd 2009-07-16 02:55:27 UTC (rev 1345) @@ -66,7 +66,7 @@ \value{ Matrix containing the interleaved rows of the function arguments. } -\author{ Gregory R. Warnes \email{wa...@bs...} +\author{ Gregory R. Warnes \email{gr...@ra...} } \seealso{ \code{\link{cbind}}, \code{\link{rbind}}, \code{\link{combine}} } Modified: trunk/gdata/man/matchcols.Rd =================================================================== --- trunk/gdata/man/matchcols.Rd 2009-07-16 02:52:07 UTC (rev 1344) +++ trunk/gdata/man/matchcols.Rd 2009-07-16 02:55:27 UTC (rev 1345) @@ -20,7 +20,7 @@ none of the patterns specified in \code{without}. } -\author{Gregory R. Warnes \email{wa...@bs...}} +\author{Gregory R. Warnes \email{gr...@ra...}} \seealso{ \code{\link[base]{grep}} } \examples{ Modified: trunk/gdata/man/nobs.Rd =================================================================== --- trunk/gdata/man/nobs.Rd 2009-07-16 02:52:07 UTC (rev 1344) +++ trunk/gdata/man/nobs.Rd 2009-07-16 02:55:27 UTC (rev 1345) @@ -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{wa...@bs...} } +\author{ Gregory R. Warnes \email{gr...@ra...} } \seealso{ \code{\link{is.na}}, \code{\link{length}} } Modified: trunk/gdata/man/rename.vars.Rd =================================================================== --- trunk/gdata/man/rename.vars.Rd 2009-07-16 02:52:07 UTC (rev 1344) +++ trunk/gdata/man/rename.vars.Rd 2009-07-16 02:55:27 UTC (rev 1345) @@ -49,7 +49,7 @@ } \author{Code by Don MacQueen \email{macq\@llnl.gov}. Documentation by Gregory R. Warnes - \email{wa...@bs...} } + \email{gr...@ra...} } \seealso{ \code{\link{names}}, \code{\link{colnames}}, \code{\link{data.frame}} Modified: trunk/gdata/man/reorder.Rd =================================================================== --- trunk/gdata/man/reorder.Rd 2009-07-16 02:52:07 UTC (rev 1344) +++ trunk/gdata/man/reorder.Rd 2009-07-16 02:55:27 UTC (rev 1345) @@ -56,7 +56,7 @@ A new factor with reordered levels } -\author{Gregory R. Warnes \email{wa...@bs...}} +\author{Gregory R. Warnes \email{gr...@ra...}} \seealso{\code{\link{factor}} and \code{\link[stats]{reorder}}} Modified: trunk/gdata/man/trim.Rd =================================================================== --- trunk/gdata/man/trim.Rd 2009-07-16 02:52:07 UTC (rev 1344) +++ trunk/gdata/man/trim.Rd 2009-07-16 02:55:27 UTC (rev 1345) @@ -32,7 +32,7 @@ \value{ \code{s} with all leading and trailing spaces removed in its elements. } -\author{Gregory R. Warnes \email{wa...@bs...} with +\author{Gregory R. Warnes \email{gr...@ra...} 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 2009-07-16 02:52:07 UTC (rev 1344) +++ trunk/gdata/man/unmatrix.Rd 2009-07-16 02:55:27 UTC (rev 1345) @@ -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{wa...@bs...} } +\author{Gregory R. Warnes \email{gr...@ra...} } \seealso{ \code{\link[base]{as.vector}} } \examples{ # simple, useless example Modified: trunk/gdata/man/upperTriangle.Rd =================================================================== --- trunk/gdata/man/upperTriangle.Rd 2009-07-16 02:52:07 UTC (rev 1344) +++ trunk/gdata/man/upperTriangle.Rd 2009-07-16 02:55:27 UTC (rev 1345) @@ -16,7 +16,7 @@ %- maybe also 'usage' for other objects documented here. \arguments{ \item{x}{Matrix} - \item{diag}{Logical. If code{TRUE}, include the matrix diagonal.} + \item{diag}{Logical. If \code{TRUE}, include the matrix diagonal.} \item{value}{Either a single value or a vector of length equal to that of the current upper/lower triangular. Should be of a mode which can be coerced to that of \code{x}.} @@ -28,7 +28,7 @@ replace the upper or lower traingular area of the matrix with the provided value(s). } -\author{Gregory R. Warnes \email{wa...@bs...}} +\author{Gregory R. Warnes \email{gr...@ra...}} \seealso{ \code{\link[base]{diag}} } \examples{ x <- matrix( 1:25, nrow=5, ncol=5) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2009-07-16 03:23:11
|
Revision: 1349 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1349&view=rev Author: warnes Date: 2009-07-16 03:23:06 +0000 (Thu, 16 Jul 2009) Log Message: ----------- Add contents of \value section for resample() man page Modified Paths: -------------- trunk/gdata/inst/doc/mapLevels.pdf trunk/gdata/inst/doc/unknown.pdf trunk/gdata/man/resample.Rd Modified: trunk/gdata/inst/doc/mapLevels.pdf =================================================================== (Binary files differ) Modified: trunk/gdata/inst/doc/unknown.pdf =================================================================== (Binary files differ) Modified: trunk/gdata/man/resample.Rd =================================================================== --- trunk/gdata/man/resample.Rd 2009-07-16 03:15:58 UTC (rev 1348) +++ trunk/gdata/man/resample.Rd 2009-07-16 03:23:06 UTC (rev 1349) @@ -25,7 +25,7 @@ have identical behavior. } \value{ - + Vector of the same length as the input, with the elements permuted. } \author{Gregory R. Warnes \email{gr...@ra...} } \seealso{ \code{\link{sample}} } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ar...@us...> - 2009-12-06 03:12:28
|
Revision: 1368 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1368&view=rev Author: arnima Date: 2009-12-06 03:12:14 +0000 (Sun, 06 Dec 2009) Log Message: ----------- Improved ll() so user can limit output to specified classes Modified Paths: -------------- trunk/gdata/R/ll.R trunk/gdata/man/ll.Rd Modified: trunk/gdata/R/ll.R =================================================================== --- trunk/gdata/R/ll.R 2009-11-16 13:51:10 UTC (rev 1367) +++ trunk/gdata/R/ll.R 2009-12-06 03:12:14 UTC (rev 1368) @@ -1,23 +1,23 @@ -ll <- function(pos=1, unit="KB", digits=0, dimensions=FALSE, function.dim="", - sort.elements=FALSE, ...) +ll <- function(pos=1, unit="KB", digits=0, dim=FALSE, sort=FALSE, class=NULL, + invert=FALSE, ...) { - get.object.classname <- function(object.name, pos) + get.object.class <- function(object.name, pos) { object <- get(object.name, pos=pos) - classname <- class(object)[1] - return(classname) + class <- class(object)[1] + return(class) } - get.object.dimensions <- function(object.name, pos) + get.object.dim <- function(object.name, pos) { object <- get(object.name, pos=pos) if(class(object)[1] == "function") - dimensions <- function.dim + dim <- "" else if(!is.null(dim(object))) - dimensions <- paste(dim(object), collapse=" x ") + dim <- paste(dim(object), collapse=" x ") else - dimensions <- length(object) - return(dimensions) + dim <- length(object) + return(dim) } get.object.size <- function(object.name, pos) @@ -54,33 +54,42 @@ else if(environmentName(as.environment(pos)) == "Autoloads") { object.frame <- data.frame(rep("function",length(ls(pos,...))), - rep(0,length(ls(pos,...))), row.names=ls(pos,...)) - if(dimensions) + rep(0,length(ls(pos,...))), + row.names=ls(pos,...)) + if(dim) { - object.frame <- cbind(object.frame, rep(function.dim,nrow(object.frame))) - names(object.frame) <- c("Class", unit, "Dimensions") + object.frame <- cbind(object.frame, rep("",nrow(object.frame))) + names(object.frame) <- c("Class", unit, "Dim") } else names(object.frame) <- c("Class", unit) } else { - class.vector <- sapply(ls(pos,...), get.object.classname, pos=pos) + class.vector <- sapply(ls(pos,...), get.object.class, pos=pos) size.vector <- sapply(ls(pos,...), get.object.size, pos=pos) size.vector <- round(size.vector/denominator, digits) object.frame <- data.frame(class.vector=class.vector, - size.vector=size.vector, row.names=names(size.vector)) + size.vector=size.vector, + row.names=names(size.vector)) names(object.frame) <- c("Class", unit) - if(dimensions) - object.frame <- cbind(object.frame, Dim=sapply(ls(pos,...), - get.object.dimensions, pos=pos)) + if(dim) + object.frame <- cbind(object.frame, + Dim=sapply(ls(pos,...),get.object.dim,pos=pos)) } if(was.list) { detach(pos=2) - if(!sort.elements) + if(!sort) object.frame <- object.frame[original.rank, ] } + if(!is.null(class)) + { + include <- object.frame$Class %in% class + if(invert) + include <- !include + object.frame <- object.frame[include,] + } return(object.frame) } Modified: trunk/gdata/man/ll.Rd =================================================================== --- trunk/gdata/man/ll.Rd 2009-11-16 13:51:10 UTC (rev 1367) +++ trunk/gdata/man/ll.Rd 2009-12-06 03:12:14 UTC (rev 1368) @@ -9,8 +9,8 @@ object, its elements are listed and described. } \usage{ -ll(pos=1, unit="KB", digits=0, dimensions=FALSE, function.dim="", - sort.elements=FALSE, ...) +ll(pos=1, unit="KB", digits=0, dim=FALSE, sort=FALSE, class=NULL, + invert=FALSE, ...) } \arguments{ \item{pos}{environment position number, environment name, data frame, @@ -19,10 +19,12 @@ "MB", or first letter.} \item{digits}{number of decimals to display when rounding object size.} - \item{dimensions}{whether object dimensions should be returned.} - \item{function.dim}{value to report as the dimension of function - objects.} - \item{sort.elements}{whether elements should be sorted by name.} + \item{dim}{whether object dimensions should be returned.} + \item{sort}{whether elements should be sorted by name.} + \item{class}{character vector for limiting the output to specified + classes.} + \item{invert}{whether to invert the \code{class} filter, so specified + classes are excluded.} \item{...}{passed to \code{ls()}.} } \details{ @@ -54,7 +56,7 @@ ll() ll(all=TRUE) ll("package:base") -ll("package:base")[ll("package:base")$Class!="function",] +ll("package:base", class="function", invert=TRUE) data(infert) ll(infert) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ar...@us...> - 2009-12-06 22:34:43
|
Revision: 1369 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1369&view=rev Author: arnima Date: 2009-12-06 22:34:29 +0000 (Sun, 06 Dec 2009) Log Message: ----------- Minor improvements of Args(). Modified Paths: -------------- trunk/gdata/R/Args.R trunk/gdata/man/Args.Rd Modified: trunk/gdata/R/Args.R =================================================================== --- trunk/gdata/R/Args.R 2009-12-06 03:12:14 UTC (rev 1368) +++ trunk/gdata/R/Args.R 2009-12-06 22:34:29 UTC (rev 1369) @@ -1,4 +1,4 @@ -Args <- function(name, sort.args=FALSE) +Args <- function(name, sort=FALSE) { a <- formals(get(as.character(substitute(name)), pos=1)) if(is.null(a)) @@ -8,7 +8,7 @@ char <- sapply(a, is.character) arg.values[char] <- paste("\"", arg.values[char], "\"", sep="") - if(sort.args) + if(sort) { ord <- order(arg.labels) if(any(arg.labels == "...")) Modified: trunk/gdata/man/Args.Rd =================================================================== --- trunk/gdata/man/Args.Rd 2009-12-06 03:12:14 UTC (rev 1368) +++ trunk/gdata/man/Args.Rd 2009-12-06 22:34:29 UTC (rev 1369) @@ -12,12 +12,17 @@ } \arguments{ \item{name}{a function or function name.} - \item{sort.args}{whether arguments should be sorted.} + \item{sort}{whether arguments should be sorted.} } \value{ A data frame with named rows and a single column called \code{value}, containing the default value of each argument. } +\note{ + In recent versions of \R, primitive functions like \code{sum} and + \code{all} have no formal arguments. See the \code{\link{formals}} + help page. +} \author{Arni Magnusson \email{arnima@u.washington.edu}} \seealso{ \code{\link{args}}, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ar...@us...> - 2010-01-22 13:06:46
|
Revision: 1371 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1371&view=rev Author: arnima Date: 2010-01-22 13:06:33 +0000 (Fri, 22 Jan 2010) Log Message: ----------- Many small improvements to documentation of Arni's five functions Modified Paths: -------------- trunk/gdata/R/Args.R trunk/gdata/R/env.R trunk/gdata/R/is.what.R trunk/gdata/R/keep.R trunk/gdata/R/ll.R trunk/gdata/man/Args.Rd trunk/gdata/man/env.Rd trunk/gdata/man/is.what.Rd trunk/gdata/man/keep.Rd trunk/gdata/man/ll.Rd Modified: trunk/gdata/R/Args.R =================================================================== --- trunk/gdata/R/Args.R 2010-01-22 12:45:21 UTC (rev 1370) +++ trunk/gdata/R/Args.R 2010-01-22 13:06:33 UTC (rev 1371) @@ -23,4 +23,3 @@ invisible(output) } - Modified: trunk/gdata/R/env.R =================================================================== --- trunk/gdata/R/env.R 2010-01-22 12:45:21 UTC (rev 1370) +++ trunk/gdata/R/env.R 2010-01-22 13:06:33 UTC (rev 1371) @@ -35,4 +35,3 @@ print(env.frame, right=FALSE) invisible(env.frame) } - Modified: trunk/gdata/R/is.what.R =================================================================== --- trunk/gdata/R/is.what.R 2010-01-22 12:45:21 UTC (rev 1370) +++ trunk/gdata/R/is.what.R 2010-01-22 13:06:33 UTC (rev 1371) @@ -24,4 +24,3 @@ return(output) } - Modified: trunk/gdata/R/keep.R =================================================================== --- trunk/gdata/R/keep.R 2010-01-22 12:45:21 UTC (rev 1370) +++ trunk/gdata/R/keep.R 2010-01-22 13:06:33 UTC (rev 1371) @@ -21,4 +21,3 @@ else return(ls(1,all.names=all)[-keep.elements]) } - Modified: trunk/gdata/R/ll.R =================================================================== --- trunk/gdata/R/ll.R 2010-01-22 12:45:21 UTC (rev 1370) +++ trunk/gdata/R/ll.R 2010-01-22 13:06:33 UTC (rev 1371) @@ -93,4 +93,3 @@ return(object.frame) } - Modified: trunk/gdata/man/Args.Rd =================================================================== --- trunk/gdata/man/Args.Rd 2010-01-22 12:45:21 UTC (rev 1370) +++ trunk/gdata/man/Args.Rd 2010-01-22 13:06:33 UTC (rev 1371) @@ -1,14 +1,12 @@ \name{Args} \alias{Args} -\title{ - Formatted Argument List of a Function -} +\title{Describe Function Arguments} \description{ Display function argument names and corresponding default values, formatted in two columns for easy reading. } \usage{ -Args(name, sort.args = FALSE) +Args(name, sort=FALSE) } \arguments{ \item{name}{a function or function name.} @@ -23,16 +21,17 @@ \code{all} have no formal arguments. See the \code{\link{formals}} help page. } -\author{Arni Magnusson \email{arnima@u.washington.edu}} +\author{Arni Magnusson} \seealso{ - \code{\link{args}}, - \code{\link{formals}}, - \code{\link{help}}. + \code{Args} is a verbose alternative to \code{\link{args}}, based on + \code{\link{formals}}. + + \code{\link{help}} also describes function arguments. } \examples{ Args(glm) Args(scan) -Args(legend) +Args(legend, sort=TRUE) } % Programming \keyword{programming} Modified: trunk/gdata/man/env.Rd =================================================================== --- trunk/gdata/man/env.Rd 2010-01-22 12:45:21 UTC (rev 1370) +++ trunk/gdata/man/env.Rd 2010-01-22 13:06:33 UTC (rev 1371) @@ -1,8 +1,6 @@ \name{env} \alias{env} -\title{ - Display Information about All Loaded Environments -} +\title{Describe All Loaded Environments} \description{ Display name, number of objects, and size of all loaded environments. } @@ -10,14 +8,11 @@ env(unit="KB", digits=0) } \arguments{ - \item{unit}{required unit for displaying environment size: "bytes", - "KB", "MB", or first letter.} + \item{unit}{unit for displaying environment size: "bytes", "KB", "MB", + or first letter.} \item{digits}{number of decimals to display when rounding environment size.} } -\details{ - A verbose alternative to \code{search()}. -} \value{ A data frame with the following columns: \item{Environment}{environment name.} @@ -27,11 +22,12 @@ \note{ The name of the environment size column is the same as the unit used. } -\author{Arni Magnusson \email{arnima@u.washington.edu}} +\author{Arni Magnusson} \seealso{ - \code{\link{search}} displays environment names. + \code{env} is a verbose alternative to \code{\link{search}}. - \code{\link{ll}} is related to \code{env}. + \code{\link{ll}} is a related function that describes objects in an + environment. } \examples{ \dontrun{ Modified: trunk/gdata/man/is.what.Rd =================================================================== --- trunk/gdata/man/is.what.Rd 2010-01-22 12:45:21 UTC (rev 1370) +++ trunk/gdata/man/is.what.Rd 2010-01-22 13:06:33 UTC (rev 1371) @@ -1,25 +1,32 @@ \name{is.what} \alias{is.what} -\title{ - Run Multiple is.* Tests on a Given Object -} +\title{Run Multiple is.* Tests on a Given Object} \description{ - Run multiple \code{is.*} tests on a given object, such as - \code{is.numeric()}, \code{is.list()}, ... + Run multiple \code{is.*} tests on a given object: \code{is.na}, + \code{is.numeric}, and many others. } \usage{ -is.what(object, verbose = FALSE) +is.what(object, verbose=FALSE) } \arguments{ - \item{object}{any R object.} + \item{object}{any \R object.} \item{verbose}{whether negative tests should be included in output.} } \value{ A character vector containing positive tests, or when \code{verbose} is \code{TRUE}, a data frame showing all test results. } -\author{Arni Magnusson \email{arnima@u.washington.edu}, inspired by - \code{demo(is.things)}.} +\author{Arni Magnusson, inspired by \code{demo(is.things)}.} +\note{ + The following procedure is used to look for valid tests: + \enumerate{ + \item{Find all objects named \code{is.*} in all loaded + environments.} + \item{Discard objects that are not functions.} + \item{Include test result only if it is of class \code{"logical"}, + not an \code{NA}, and of length 1.} + } +} \seealso{ \code{\link{is.na}} and \code{\link{is.numeric}} are commonly used tests. @@ -28,6 +35,7 @@ is.what(pi) is.what(NA, verbose=TRUE) is.what(lm(1~1)) +is.what(is.what) } % Basics \keyword{classes} Modified: trunk/gdata/man/keep.Rd =================================================================== --- trunk/gdata/man/keep.Rd 2010-01-22 12:45:21 UTC (rev 1370) +++ trunk/gdata/man/keep.Rd 2010-01-22 13:06:33 UTC (rev 1371) @@ -1,13 +1,11 @@ \name{keep} \alias{keep} -\title{ - Remove All Objects, Except Those Specified -} +\title{Remove All Objects, Except Those Specified} \description{ Remove all objects from the default workspace, except those specified. } \usage{ -keep(..., list = character(0), all = FALSE, sure = FALSE) +keep(..., list=character(0), all=FALSE, sure=FALSE) } \arguments{ \item{...}{objects to be kept, specified one by one, quoted or @@ -19,20 +17,18 @@ objects that would have been removed.} } \details{ - Convenient interface to \code{rm()} when removing most objects from - the default workspace. - - Implemented with a few safety caps: objects whose name starts with a - period \sQuote{\code{.}} are not removed, and \code{sure=TRUE} is - required to perform the removal. + Implemented with safety caps: objects whose name starts with a + \code{.} are not removed unless \code{all=TRUE}, and an explicit + \code{sure=TRUE} is required to remove anything. } \value{ A character vector containing object names, or \code{NULL} when \code{sure} is \code{TRUE}. } -\author{Arni Magnusson \email{arnima@u.washington.edu}} +\author{Arni Magnusson} \seealso{ - \code{\link{rm}}. + \code{keep} is a convenient interface to \code{\link{rm}} when + removing most objects from the default workspace. } \examples{ data(women, cars) Modified: trunk/gdata/man/ll.Rd =================================================================== --- trunk/gdata/man/ll.Rd 2010-01-22 12:45:21 UTC (rev 1370) +++ trunk/gdata/man/ll.Rd 2010-01-22 13:06:33 UTC (rev 1371) @@ -1,8 +1,6 @@ \name{ll} \alias{ll} -\title{ - Display Information about Objects or Elements -} +\title{Describe Objects or Elements} \description{ Display name, class, size, and dimensions of each object in a given environment. Alternatively, if the main argument is a list-like @@ -14,9 +12,9 @@ } \arguments{ \item{pos}{environment position number, environment name, data frame, - list, model, or any object that \code{is.list()}.} - \item{unit}{required unit for displaying object size: "bytes", "KB", - "MB", or first letter.} + list, model, or any object that \code{is.list}.} + \item{unit}{unit for displaying object size: "bytes", "KB", "MB", or + first letter.} \item{digits}{number of decimals to display when rounding object size.} \item{dim}{whether object dimensions should be returned.} @@ -25,32 +23,25 @@ classes.} \item{invert}{whether to invert the \code{class} filter, so specified classes are excluded.} - \item{...}{passed to \code{ls()}.} + \item{...}{passed to \code{ls}.} } -\details{ - A verbose alternative to \code{ls()} and \code{names()}. -} \value{ A data frame with named rows and the following columns: \item{Class}{object class.} - \item{KB}{object size \emph{(see notes)}.} + \item{KB}{object size \emph{(see note)}.} \item{Dim}{object dimensions \emph{(optional)}.} } -\note{ - The name of the object size column is the same as the unit used. -} - -\author{Arni Magnusson \email{arnima@u.washington.edu}, with a - contribution by Jim Rogers \email{jam...@pf...}} - +\note{The name of the object size column is the same as the unit used.} +\author{Arni Magnusson, with a contribution by Jim Rogers} \seealso{ - \code{\link{ls}} displays names of objects in a given environment. + \code{ll} is a verbose alternative to \code{\link{ls}} (objects in an + environment) and \code{\link{names}} (elements in a list-like object). - \code{\link[base]{names}}, \code{\link[utils]{str}}, and - \code{\link[base]{summary}} display different information about - list-like elements. + \code{\link{str}} and \code{\link{summary}} also describe elements in + a list-like objects. - \code{\link{env}} is related to \code{ll}. + \code{\link{env}} is a related function that describes all loaded + environments. } \examples{ ll() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ggr...@us...> - 2010-01-24 02:28:18
|
Revision: 1389 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1389&view=rev Author: ggrothendieck2 Date: 2010-01-24 02:28:11 +0000 (Sun, 24 Jan 2010) Log Message: ----------- added sheetNames.Rd (documenting sheetNames/sheetCount) and updated NAMESPACE file. Modified Paths: -------------- trunk/gdata/NAMESPACE Added Paths: ----------- trunk/gdata/man/sheetNames.Rd Modified: trunk/gdata/NAMESPACE =================================================================== --- trunk/gdata/NAMESPACE 2010-01-24 02:05:51 UTC (rev 1388) +++ trunk/gdata/NAMESPACE 2010-01-24 02:28:11 UTC (rev 1389) @@ -24,6 +24,8 @@ remove.vars, reorder.factor, resample, + sheetCount, + sheetNames, trim, trimSum, unmatrix, Added: trunk/gdata/man/sheetNames.Rd =================================================================== --- trunk/gdata/man/sheetNames.Rd (rev 0) +++ trunk/gdata/man/sheetNames.Rd 2010-01-24 02:28:11 UTC (rev 1389) @@ -0,0 +1,42 @@ +\name{sheetNames} +\Rdversion{1.1} +\alias{sheetCount} +\alias{sheetNames} +\title{ +Count sheets in Excel xls spreadsheet. +} +\description{ +Count the sheets in an Excel xls spreadsheet. +} +\usage{ +sheetCount(xls, verbose = FALSE, perl = "perl") +sheetNames(xls, verbose = FALSE, perl = "perl") +} +%- maybe also 'usage' for other objects documented here. +\arguments{ + \item{xls}{ +File path to spreadsheet. Is downloaded if it begins with \code{"http://"}.} + \item{verbose}{ + If \code{TRUE} additional information displayed. +} + \item{perl}{ + Path and file of perl interpreter or just \code{"perl"} if perl on path. +} +} +\value{ +\code{sheetCount} returns the number of sheets in the spreadsheet +and \code{sheetNames} returns +a character vector containing the sheet names in the spreadsheet. +} + +\seealso{ + \code{\link{read.xls}}, \code{\link{xls2csv}}. +} +\examples{ + xlsfile <- system.file("xls", "iris.xls", package = "gdata") + xlsfile + + sheetCount(xlsfile) + +} +\keyword{ misc } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2010-01-24 08:33:40
|
Revision: 1398 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1398&view=rev Author: warnes Date: 2010-01-24 08:33:34 +0000 (Sun, 24 Jan 2010) Log Message: ----------- Update for 2.7.0 release Modified Paths: -------------- trunk/gdata/DESCRIPTION trunk/gdata/inst/NEWS trunk/gdata/inst/doc/mapLevels.pdf trunk/gdata/inst/doc/unknown.pdf Modified: trunk/gdata/DESCRIPTION =================================================================== --- trunk/gdata/DESCRIPTION 2010-01-24 08:21:24 UTC (rev 1397) +++ trunk/gdata/DESCRIPTION 2010-01-24 08:33:34 UTC (rev 1398) @@ -3,8 +3,8 @@ Description: Various R programming tools for data manipulation Depends: R (>= 2.6.0) Imports: gtools -Version: 2.6.1 -Date: 2009-08-19 +Version: 2.7.0 +Date: 2010-01-25 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 Modified: trunk/gdata/inst/NEWS =================================================================== --- trunk/gdata/inst/NEWS 2010-01-24 08:21:24 UTC (rev 1397) +++ trunk/gdata/inst/NEWS 2010-01-24 08:33:34 UTC (rev 1398) @@ -1,3 +1,41 @@ +CHANGES IN 2.7.0 (2010-01-25) +----------------------------- + +Enhancements: + +- read.xls() now supports Excel 2007 'xlsx' files. + +- read.xls() now allows specification of worksheet by name + +- read.xls() now supports ftp URLs. + +- Improved ll() so user can limit output to specified classes + + + +New Functions: + +- sheetCount() and sheetNames() to determine the number and names of + worksheets in an Excel file, respecively. + +Bug Fixes: + +- Fix formatting warning in frameApply(). + +- Modify unit tests to avoid issues related to zime zones. + +- Resolve crash of "ll(.GlobalEnv)" + +- + +CHANGES IN 2.6.1 (2009-07-15) +----------------------------- + +Bug Fixes + +- Modify unit tests to avoid issues related to zime zones. + + CHANGES IN 2.6.0 (2009-07-15) ----------------------------- Modified: trunk/gdata/inst/doc/mapLevels.pdf =================================================================== (Binary files differ) Modified: trunk/gdata/inst/doc/unknown.pdf =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2010-01-28 19:58:32
|
Revision: 1419 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1419&view=rev Author: warnes Date: 2010-01-28 19:58:26 +0000 (Thu, 28 Jan 2010) Log Message: ----------- Update for release 2.7.1 Modified Paths: -------------- trunk/gdata/DESCRIPTION trunk/gdata/inst/NEWS Modified: trunk/gdata/DESCRIPTION =================================================================== --- trunk/gdata/DESCRIPTION 2010-01-28 19:56:21 UTC (rev 1418) +++ trunk/gdata/DESCRIPTION 2010-01-28 19:58:26 UTC (rev 1419) @@ -3,8 +3,8 @@ Description: Various R programming tools for data manipulation Depends: R (>= 2.6.0) Imports: gtools -Version: 2.7.0 -Date: 2010-01-25 +Version: 2.7.1 +Date: 2010-01-27 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 Modified: trunk/gdata/inst/NEWS =================================================================== --- trunk/gdata/inst/NEWS 2010-01-28 19:56:21 UTC (rev 1418) +++ trunk/gdata/inst/NEWS 2010-01-28 19:58:26 UTC (rev 1419) @@ -1,6 +1,14 @@ CHANGES IN 2.7.0 (2010-01-25) ----------------------------- +Bug Fixes: + +- Fix building of Perl libraries on Win32 + + +CHANGES IN 2.7.0 (2010-01-25) +----------------------------- + Enhancements: - read.xls() now supports Excel 2007 'xlsx' files. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ggr...@us...> - 2010-02-19 15:36:34
|
Revision: 1421 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1421&view=rev Author: ggrothendieck2 Date: 2010-02-19 15:36:26 +0000 (Fri, 19 Feb 2010) Log Message: ----------- added findPerl to locate ActiveState Perl on Windows if perl= not specified and Rtools perl would have otherwise been used. Also added INSTALL file. Modified Paths: -------------- trunk/gdata/R/dQuote.ascii.R trunk/gdata/R/read.xls.R trunk/gdata/R/sheetCount.R trunk/gdata/inst/NEWS Added Paths: ----------- trunk/gdata/INSTALL Added: trunk/gdata/INSTALL =================================================================== --- trunk/gdata/INSTALL (rev 0) +++ trunk/gdata/INSTALL 2010-02-19 15:36:26 UTC (rev 1421) @@ -0,0 +1,16 @@ + +Windows +======= + +On Windows, the perl based routines (read.xls, xls2sep, xls2csv, xls2tab, +xls2tsv, sheetNames, sheetCount) will not work with the perl in Rtools +but will work with ActiveState perl. + +If you have ActiveState installed and the pl extension is associated with it +(which the ActiveState installer associates automatically) then these +routines will automatically locate ActiveState perl even if you omit the +perl= argument. + +Also ensure that the package was built with ActiveState Perl and not the perl +in Rtools. + Modified: trunk/gdata/R/dQuote.ascii.R =================================================================== --- trunk/gdata/R/dQuote.ascii.R 2010-02-17 14:53:16 UTC (rev 1420) +++ trunk/gdata/R/dQuote.ascii.R 2010-02-19 15:36:26 UTC (rev 1421) @@ -7,3 +7,25 @@ ## 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 +} + + Modified: trunk/gdata/R/read.xls.R =================================================================== --- trunk/gdata/R/read.xls.R 2010-02-17 14:53:16 UTC (rev 1420) +++ trunk/gdata/R/read.xls.R 2010-02-19 15:36:26 UTC (rev 1421) @@ -16,6 +16,8 @@ ## 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) con <- xls2sep(xls, sheet, verbose=verbose, ..., method=method, perl = perl) ## load the csv file Modified: trunk/gdata/R/sheetCount.R =================================================================== --- trunk/gdata/R/sheetCount.R 2010-02-17 14:53:16 UTC (rev 1420) +++ trunk/gdata/R/sheetCount.R 2010-02-19 15:36:26 UTC (rev 1421) @@ -1,8 +1,14 @@ -sheetCount <- function(xls, verbose = FALSE, perl = "perl") +sheetCount <- function(xls, verbose = FALSE, perl = "perl") { + perl <- if (missing(perl)) findPerl(verbose = verbose) + else findPerl(perl, verbose = verbose) sheetCmd(xls, cmd="sheetCount.pl", verbose=verbose, perl=perl) +} -sheetNames <- function(xls, verbose = FALSE, perl = "perl") +sheetNames <- function(xls, verbose = FALSE, perl = "perl") { + perl <- if (missing(perl)) findPerl(verbose = verbose) + else findPerl(perl, verbose = verbose) sheetCmd(xls, cmd="sheetNames.pl", verbose=verbose, perl=perl) +} sheetCmd <- function(xls, cmd="sheetCount.pl", verbose=FALSE, perl="perl") { @@ -40,6 +46,7 @@ ## ## execution command + cmd <- paste(perl, sc, dQuote.ascii(xls), sep=" ") ## ## Modified: trunk/gdata/inst/NEWS =================================================================== --- trunk/gdata/inst/NEWS 2010-02-17 14:53:16 UTC (rev 1420) +++ trunk/gdata/inst/NEWS 2010-02-19 15:36:26 UTC (rev 1421) @@ -1,3 +1,11 @@ +CHANGES IN 2.7.0 (2010-02-19) + +Enhancements: + +- on Windows attempts to locate ActiveState perl if perl= not specified and + Rtools perl would have otherwise been used in read.xls and other perl + dependent functions. + CHANGES IN 2.7.0 (2010-01-25) ----------------------------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ggr...@us...> - 2010-02-21 17:12:37
|
Revision: 1423 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1423&view=rev Author: ggrothendieck2 Date: 2010-02-21 17:12:30 +0000 (Sun, 21 Feb 2010) Log Message: ----------- isOpen problems fixed (isOpen must have changed in R since this worked in earlier versions). Also nba.xls link in read.xls.Rd disappeared. Replaced with similar link. Modified Paths: -------------- trunk/gdata/R/read.xls.R trunk/gdata/man/read.xls.Rd Modified: trunk/gdata/R/read.xls.R =================================================================== --- trunk/gdata/R/read.xls.R 2010-02-20 11:32:43 UTC (rev 1422) +++ trunk/gdata/R/read.xls.R 2010-02-21 17:12:30 UTC (rev 1423) @@ -5,7 +5,11 @@ { con <- tfn <- NULL on.exit({ - if (inherits(con, "connection") && isOpen(con)) close(con) + err <- FALSE + if (inherits(con, "connection")) { + tryCatch(op <- isOpen(con), error = function(x) err <<- TRUE) + if (!err && op) close(con) + } if (file.exists(tfn)) file.remove(tfn) }) Modified: trunk/gdata/man/read.xls.Rd =================================================================== --- trunk/gdata/man/read.xls.Rd 2010-02-20 11:32:43 UTC (rev 1422) +++ trunk/gdata/man/read.xls.Rd 2010-02-21 17:12:30 UTC (rev 1423) @@ -86,7 +86,7 @@ iris <- read.xls(xlsfile, perl="/usr/bin/perl") # read xls file from net - nba.url <- "http://lcb1.uoregon.edu/sergiok/DSC330HSP04/week5/NBA.xls" + nba.url <- "http://mgtclass.mgt.unm.edu/Bose/Excel/Tutorial.05/Cases/NBA.xls" nba <- read.xls(nba.url) # read xls file ignoring all lines prior to first containing State This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |
From: <wa...@us...> - 2010-05-03 13:35:21
|
Revision: 1437 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1437&view=rev Author: warnes Date: 2010-05-03 13:35:11 +0000 (Mon, 03 May 2010) Log Message: ----------- Add .onAttach function to check & inform user if perl is available, to check whether XLS and XLSX formats are avaiable, and to run the (new) installXLSXModules() functon to attempt to install the necessar libraries if not. Added installXLSXModules() function. Modified Paths: -------------- trunk/gdata/DESCRIPTION trunk/gdata/NAMESPACE trunk/gdata/inst/perl/install_modules.pl trunk/gdata/inst/perl/module_tools.pl trunk/gdata/tests/test.read.xls.R Added Paths: ----------- trunk/gdata/R/installXLSXModules.R trunk/gdata/R/onAttach.R Modified: trunk/gdata/DESCRIPTION =================================================================== --- trunk/gdata/DESCRIPTION 2010-05-02 13:56:43 UTC (rev 1436) +++ trunk/gdata/DESCRIPTION 2010-05-03 13:35:11 UTC (rev 1437) @@ -3,8 +3,8 @@ Description: Various R programming tools for data manipulation Depends: R (>= 2.6.0) Imports: gtools -Version: 2.7.2 -Date: 2010-04-02 +Version: 2.8.0 +Date: 2010-04-03 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 Modified: trunk/gdata/NAMESPACE =================================================================== --- trunk/gdata/NAMESPACE 2010-05-02 13:56:43 UTC (rev 1436) +++ trunk/gdata/NAMESPACE 2010-05-03 13:35:11 UTC (rev 1437) @@ -1,5 +1,6 @@ export( + .onAttach, Args, aggregate.table, bindData, @@ -10,6 +11,7 @@ elem, env, frameApply, + installXLSXModules, interleave, is.what, keep, Added: trunk/gdata/R/installXLSXModules.R =================================================================== --- trunk/gdata/R/installXLSXModules.R (rev 0) +++ trunk/gdata/R/installXLSXModules.R 2010-05-03 13:35:11 UTC (rev 1437) @@ -0,0 +1,58 @@ +## s$Id: read.xls.R 1423 2010-02-21 17:12:30Z ggrothendieck2 $ + +installXLSXModules <- 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 <- "install_modules.pl" + sc <- file.path(perl.dir, cmd) + + ## + ## + + ## + ## execution command + + cmd <- paste(perl, sc, sep=" ") + + ## + + if(verbose) + { + cat("\n") + cat("Attempting to automaticall install Perl libraries to support XLSX (Excel 2007+) file format...\n") + cat("\n") + } + + ## + + output <- system(cmd, intern=TRUE) + + ## + + if(verbose) cat("Results: ", output, "\n") + + ## + + if( "XLSX" %in% xlsFormats(perl=perl, verbose=verbose) ) + { + cat("\nPerl XLSX support libraries successfully installed.\n\n") + invisible(TRUE) + } + else + { + stop("\nUnable to install Perl XLSX support libraries.\n\n") + invisible(FALSE) + } +} Added: trunk/gdata/R/onAttach.R =================================================================== --- trunk/gdata/R/onAttach.R (rev 0) +++ trunk/gdata/R/onAttach.R 2010-05-03 13:35:11 UTC (rev 1437) @@ -0,0 +1,78 @@ +.onAttach <- function(libname, pkgname) + { + show <- function(...) + writeLines(strwrap( x=list(...), prefix="gdata: " )) + + + try( + { + + ## 1 - Can we access perl? + hasPerl <- try( findPerl(), silent=TRUE) + if(inherits(hasPerl, "try-error")) + show( + " + Unable to locate valid perl interpreter + \n + \n + read.xls() will be unable to read Excel XLS and XLSX files + unless the 'perl=' argument is used to specify the location of + a valid perl intrpreter. + \n + \n + (To avoid display of this message in the future, please ensure perl + is installed and available on the executable search path.) + ") + + + formats <- try(xlsFormats(),silent=TRUE) + msg <- FALSE + ## 2 - Are the libraries for XLS present? + if( !("XLS" %in% formats) ) + { + show( + "Unable to load perl libaries needed by read.xls()", + " to support 'XLX' (Excel 97-2004) files." + ) + msg <- TRUE + } + else + { + show( + "read.xls support for 'XLS' (Excel 97-2004) files ENABLED.") + } + + show("\n") + + ## 3 - Are the libbaries for XLSX present? + if( !("XLSX" %in% formats) ) + { + show( + "Unable to load perl libaries needed by read.xls()", + " to support 'XLSX' (Excel 2007+) files." + ) + msg <- TRUE + } + else + { + show( + "read.xls support for 'XLSX' (Excel 2007+) files ENABLED." + ) + } + + + + if(msg) + { + show("\n") + + show( + " Run the function 'installXLSXModules()'", + " to automatically download and install the perl", + " libaries needed for Excel XLS and XLSX formats." + ) + } + + }) + + } Modified: trunk/gdata/inst/perl/install_modules.pl =================================================================== --- trunk/gdata/inst/perl/install_modules.pl 2010-05-02 13:56:43 UTC (rev 1436) +++ trunk/gdata/inst/perl/install_modules.pl 2010-05-03 13:35:11 UTC (rev 1437) @@ -1,4 +1,11 @@ +#!/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); Modified: trunk/gdata/inst/perl/module_tools.pl =================================================================== --- trunk/gdata/inst/perl/module_tools.pl 2010-05-02 13:56:43 UTC (rev 1436) +++ trunk/gdata/inst/perl/module_tools.pl 2010-05-03 13:35:11 UTC (rev 1437) @@ -80,7 +80,7 @@ { my($mod, $obj, $here); - $here = getcwd(); + $here = dirname($0); # load the module require CPAN; Modified: trunk/gdata/tests/test.read.xls.R =================================================================== --- trunk/gdata/tests/test.read.xls.R 2010-05-02 13:56:43 UTC (rev 1436) +++ trunk/gdata/tests/test.read.xls.R 2010-05-03 13:35:11 UTC (rev 1437) @@ -1,5 +1,9 @@ library(gdata) +if ( ! 'XLSX' %in% xlsFormats() ) + { + try( installXLSXModules() ) + } # iris.xls is included in the gregmisc package for use as an example xlsfile <- file.path(.path.package('gdata'),'xls','iris.xls') This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2010-05-03 16:26:20
|
Revision: 1439 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1439&view=rev Author: warnes Date: 2010-05-03 16:26:14 +0000 (Mon, 03 May 2010) Log Message: ----------- Rename installXLSXModules() to installXLSXsupport() and provide documentation for it. Modified Paths: -------------- trunk/gdata/NAMESPACE trunk/gdata/R/onAttach.R trunk/gdata/inst/NEWS trunk/gdata/man/xlsFormats.Rd Added Paths: ----------- trunk/gdata/R/installXLSXsupport.R trunk/gdata/man/installXLSXsupport.Rd Removed Paths: ------------- trunk/gdata/R/installXLSXModules.R Modified: trunk/gdata/NAMESPACE =================================================================== --- trunk/gdata/NAMESPACE 2010-05-03 13:48:39 UTC (rev 1438) +++ trunk/gdata/NAMESPACE 2010-05-03 16:26:14 UTC (rev 1439) @@ -11,7 +11,7 @@ elem, env, frameApply, - installXLSXModules, + installXLSXsupport, interleave, is.what, keep, Deleted: trunk/gdata/R/installXLSXModules.R =================================================================== --- trunk/gdata/R/installXLSXModules.R 2010-05-03 13:48:39 UTC (rev 1438) +++ trunk/gdata/R/installXLSXModules.R 2010-05-03 16:26:14 UTC (rev 1439) @@ -1,58 +0,0 @@ -## s$Id: read.xls.R 1423 2010-02-21 17:12:30Z ggrothendieck2 $ - -installXLSXModules <- 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 <- "install_modules.pl" - sc <- file.path(perl.dir, cmd) - - ## - ## - - ## - ## execution command - - cmd <- paste(perl, sc, sep=" ") - - ## - - if(verbose) - { - cat("\n") - cat("Attempting to automaticall install Perl libraries to support XLSX (Excel 2007+) file format...\n") - cat("\n") - } - - ## - - output <- system(cmd, intern=TRUE) - - ## - - if(verbose) cat("Results: ", output, "\n") - - ## - - if( "XLSX" %in% xlsFormats(perl=perl, verbose=verbose) ) - { - cat("\nPerl XLSX support libraries successfully installed.\n\n") - invisible(TRUE) - } - else - { - stop("\nUnable to install Perl XLSX support libraries.\n\n") - invisible(FALSE) - } -} Copied: trunk/gdata/R/installXLSXsupport.R (from rev 1438, trunk/gdata/R/installXLSXModules.R) =================================================================== --- trunk/gdata/R/installXLSXsupport.R (rev 0) +++ trunk/gdata/R/installXLSXsupport.R 2010-05-03 16:26:14 UTC (rev 1439) @@ -0,0 +1,58 @@ +## s$Id: read.xls.R 1423 2010-02-21 17:12:30Z ggrothendieck2 $ + +installXLSXsupport <- 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 <- "install_modules.pl" + sc <- file.path(perl.dir, cmd) + + ## + ## + + ## + ## execution command + + cmd <- paste(perl, sc, sep=" ") + + ## + + if(verbose) + { + cat("\n") + cat("Attempting to automaticall install Perl libraries to support XLSX (Excel 2007+) file format...\n") + cat("\n") + } + + ## + + output <- system(cmd, intern=TRUE) + + ## + + if(verbose) cat("Results: ", output, "\n") + + ## + + if( "XLSX" %in% xlsFormats(perl=perl, verbose=verbose) ) + { + cat("\nPerl XLSX support libraries successfully installed.\n\n") + invisible(TRUE) + } + else + { + stop("\nUnable to install Perl XLSX support libraries.\n\n") + invisible(FALSE) + } +} Modified: trunk/gdata/R/onAttach.R =================================================================== --- trunk/gdata/R/onAttach.R 2010-05-03 13:48:39 UTC (rev 1438) +++ trunk/gdata/R/onAttach.R 2010-05-03 16:26:14 UTC (rev 1439) @@ -67,9 +67,9 @@ show("\n") show( - " Run the function 'installXLSXModules()'", + " Run the function 'installXLSXsupport()'", " to automatically download and install the perl", - " libaries needed for Excel XLS and XLSX formats." + " libaries needed to support Excel XLS and XLSX formats." ) } Modified: trunk/gdata/inst/NEWS =================================================================== --- trunk/gdata/inst/NEWS 2010-05-03 13:48:39 UTC (rev 1438) +++ trunk/gdata/inst/NEWS 2010-05-03 16:26:14 UTC (rev 1439) @@ -12,10 +12,14 @@ If necessary perl libraries are not available, a warning message is displayed, as is a message suggesting the user run the (new) - installXLSXModules() function to attempt to install the necessary + installXLSXsupport() function to attempt to install the necessary perl libraries. +- The function function installXLSXsupport() has been provided to + install the binary perl modules that read.xls needs to support Excel + 2007+ 'XLSX' files. + CHANGES IN 2.7.3 (2010-04-02) ----------------------------- Added: trunk/gdata/man/installXLSXsupport.Rd =================================================================== --- trunk/gdata/man/installXLSXsupport.Rd (rev 0) +++ trunk/gdata/man/installXLSXsupport.Rd 2010-05-03 16:26:14 UTC (rev 1439) @@ -0,0 +1,68 @@ +\name{installXLSXsupport} +\Rdversion{1.1} +\alias{installXLSXsupport} +\title{ +Install perl modules needed for read.xls to support Excel 2007+ XLSX format +} +\description{ +Install perl modules needed for read.xls to support Excel 2007+ XLSX format +} +\usage{ +installXLSXsupport(perl = "perl", verbose = FALSE) +} +\arguments{ + \item{perl}{Path to perl interpreter (optional).} + \item{verbose}{If \code{TRUE}, show additional messages during + processing.} +} +\value{ + Either \code{TRUE} indicating that the necessary perl modules have + been successfully installed, or \code{FALSE} indicating that an error + has occured. +} +\details{ + + This function calls the perl script 'install_modules.pl' located in + the perl subdirectory of the gdata package directory (or inst/perl in + the source package). This perl script attempts to use the perl 'CPAN' + package, which should be included as part of most perl installations, + to automatically download, compile, and install the + Compress::Raw::Zlib and Spreadsheet::XLSX perl modules needed for + read.xls to support support Excel 2007+ XLSX files into the gdata + perl subdirectory. + + Since the perl modules are installed into the gdata installation + directory, the perl modules will be available until the gdata package + is replaced or removed. Since this occurs each time a new version of + gdata is installed, \code{installXLSXsupport} will need to be run each + time a new version of the gdata package is installed. + + Further, the binary Compress::Raw::Zlib package installed by + \code{installXLSXsupport} is tied to the particular version of perl + used to compile it, therefore, you will need to re-run + \code{installXLSXsupport} if you install a different perl + distribution. + + This installation process will fail if 1) perl is not available on the + search path and the \code{perl} argument is not used to specify the + path of the perl executable, 2) the perl installation is not properly + configured for installing binary packages*, 3) if the CPAN module is + not present, or 4) if the C compiler specified by the perl + installation is not present. + + \emph{In particular, \code{installXLSXsupport} will fail for the + version of perl included with the current RTools.zip package, which is + not correctly configured to allow installation of additional perl + packages. (The RTools version of perl is installed in a different + directory than the perl configuration files expect.)} + + The function \code{xlsFormats} can be used to see whether XLS and XLSX + formats are supported by the currently available perl modules. + } +\seealso{ + \code{\link{read.xls}}, \code{\link{xls2csv}}, \code{\link{xlsFormats}} +} +\examples{ + installXLSXsupport() +} +\keyword{ misc } Modified: trunk/gdata/man/xlsFormats.Rd =================================================================== --- trunk/gdata/man/xlsFormats.Rd 2010-05-03 13:48:39 UTC (rev 1438) +++ trunk/gdata/man/xlsFormats.Rd 2010-05-03 16:26:14 UTC (rev 1439) @@ -2,10 +2,10 @@ \Rdversion{1.1} \alias{xlsFormats} \title{ -Determine which XLS file formats are supported by read.xls +Check which file formats are supported by read.xls } \description{ -Determine which XLS file formats are supported by read.xls +Check which file formats are supported by read.xls } \usage{ xlsFormats(perl = "perl", verbose = FALSE) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2010-11-12 19:08:23
|
Revision: 1459 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1459&view=rev Author: warnes Date: 2010-11-12 19:08:12 +0000 (Fri, 12 Nov 2010) Log Message: ----------- Modify write.fwf() to capture and pass on additional arguments for write.table(). This resolves a bug reported by Jan Wijffels. Modified Paths: -------------- trunk/gdata/R/write.fwf.R trunk/gdata/man/write.fwf.Rd Added Paths: ----------- trunk/gdata/tests/test.write.fwf.eol.R Modified: trunk/gdata/R/write.fwf.R =================================================================== --- trunk/gdata/R/write.fwf.R 2010-11-12 02:59:29 UTC (rev 1458) +++ trunk/gdata/R/write.fwf.R 2010-11-12 19:08:12 UTC (rev 1459) @@ -5,10 +5,22 @@ ### Time-stamp: <2008-08-05 12:11:27 ggorjan> ###------------------------------------------------------------------------ -write.fwf <- function(x, file="", append=FALSE, quote=FALSE, sep=" ", - na="", rownames=FALSE, colnames=TRUE, rowCol=NULL, - justify="left", formatInfo=FALSE, quoteInfo=TRUE, - width=NULL, ...) +write.fwf <- function(x, + file="", + append=FALSE, + quote=FALSE, + sep=" ", + na="", + rownames=FALSE, + colnames=TRUE, + rowCol=NULL, + justify="left", + formatInfo=FALSE, + quoteInfo=TRUE, + width=NULL, + eol="\n", + qmethod=c("escape", "double"), + ...) { ## --- Setup --- @@ -137,12 +149,28 @@ if(colnames) { if(rownames && is.null(rowCol)) colnamesMy <- colnamesMy[-1] - write.table(t(as.matrix(colnamesMy)), file=file, append=append, - quote=quote, sep=sep, row.names=FALSE, col.names=FALSE, ...) - } + write.table(t(as.matrix(colnamesMy)), + file=file, + append=append, + quote=quote, + sep=sep, + eol=eol, + na=na, + row.names=FALSE, + col.names=FALSE, + qmethod=qmethod) + } - write.table(x=x, file=file, append=(colnames || append), quote=quote, - sep=sep, row.names=FALSE, col.names=FALSE, ...) + write.table(x=x, + file=file, + append=(colnames || append), + quote=quote, + sep=sep, + eol=eol, + na=na, + row.names=FALSE, + col.names=FALSE, + qmethod=qmethod) ## --- Return format and fixed width information --- Modified: trunk/gdata/man/write.fwf.Rd =================================================================== --- trunk/gdata/man/write.fwf.Rd 2010-11-12 02:59:29 UTC (rev 1458) +++ trunk/gdata/man/write.fwf.Rd 2010-11-12 19:08:12 UTC (rev 1459) @@ -22,7 +22,8 @@ write.fwf(x, file="", append=FALSE, quote=FALSE, sep=" ", na="", rownames=FALSE, colnames=TRUE, rowCol=NULL, justify="left", - formatInfo=FALSE, quoteInfo=TRUE, width=NULL, \dots) + formatInfo=FALSE, quoteInfo=TRUE, width=NULL, eol="\n", + qmethod=c("escape", "double"), \dots) } @@ -44,8 +45,18 @@ widths and format} \item{quoteInfo}{logical, should \code{formatInfo} account for quotes} \item{width}{numeric, width of the columns in the output} - \item{\dots}{further arguments to \code{\link{format.info}}, - \code{\link{format}} and \code{\link{write.table}}} + \item{eol}{the character(s) to print at the end of each line (row). + For example, 'eol="\\r\\n"' will produce Windows' line endings on a + Unix-alike OS, and 'eol="\\r"' will produce files as expected by Mac + OS Excel 2004.} + \item{qmethod}{a character string specifying how to deal with embedded + double quote characters when quoting strings. Must be one of + '"escape"' (default), in which case the quote character is + escaped in C style by a backslash, or '"double"', in which + case it is doubled. You can specify just the initial letter.} + \item{\dots}{further arguments to + \code{\link{format.info}} and \code{\link{format}} + } } \details{ Added: trunk/gdata/tests/test.write.fwf.eol.R =================================================================== --- trunk/gdata/tests/test.write.fwf.eol.R (rev 0) +++ trunk/gdata/tests/test.write.fwf.eol.R 2010-11-12 19:08:12 UTC (rev 1459) @@ -0,0 +1,5 @@ +library(gdata) +saveto <- tempfile(pattern = "test.txt", tmpdir = tempdir()) + +write.fwf(x = data.frame(a=1:length(LETTERS), b=LETTERS), + file=saveto, eol="\r\n") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gg...@us...> - 2011-01-15 21:59:02
|
Revision: 1465 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1465&view=rev Author: ggorjan Date: 2011-01-15 21:58:56 +0000 (Sat, 15 Jan 2011) Log Message: ----------- Adding summary method for nPairs Modified Paths: -------------- trunk/gdata/NAMESPACE trunk/gdata/R/nPairs.R trunk/gdata/inst/NEWS trunk/gdata/inst/unitTests/runit.nPairs.R trunk/gdata/man/nPairs.Rd Modified: trunk/gdata/NAMESPACE =================================================================== --- trunk/gdata/NAMESPACE 2011-01-06 19:33:26 UTC (rev 1464) +++ trunk/gdata/NAMESPACE 2011-01-15 21:58:56 UTC (rev 1465) @@ -62,6 +62,8 @@ S3method(reorder, factor) +S3method(summary, nPairs) + ## drop.levels stuff S3method(drop.levels, default) S3method(drop.levels, factor) Modified: trunk/gdata/R/nPairs.R =================================================================== --- trunk/gdata/R/nPairs.R 2011-01-06 19:33:26 UTC (rev 1464) +++ trunk/gdata/R/nPairs.R 2011-01-15 21:58:56 UTC (rev 1465) @@ -42,8 +42,22 @@ colnames(ret) <- tmp } } + class(ret) <- c("nPairs", class(ret)) ret } +summary.nPairs <- function(object, ...) +{ + n <- nrow(object) + ret <- matrix(data=0, nrow=n, ncol=n) + for(i in 1:n) { + tmp <- 1:n + tmp <- tmp[!(tmp == i)] + ret[i, tmp] <- object[i, i] - object[i, tmp] + } + dimnames(ret) <- dimnames(object) + ret +} + ###------------------------------------------------------------------------ ### nPairs.R ends here Modified: trunk/gdata/inst/NEWS =================================================================== --- trunk/gdata/inst/NEWS 2011-01-06 19:33:26 UTC (rev 1464) +++ trunk/gdata/inst/NEWS 2011-01-15 21:58:56 UTC (rev 1465) @@ -1,3 +1,12 @@ + +CHANGES IN 2.?.? (2011-??-??) +----------------------------- + +Enhancements: + +- nPairs() gains a summary method that shows how many times each variable + is known, while the other variable of a pair is not + CHANGES IN 2.8.1 (2010-11-12) ----------------------------- Modified: trunk/gdata/inst/unitTests/runit.nPairs.R =================================================================== --- trunk/gdata/inst/unitTests/runit.nPairs.R 2011-01-06 19:33:26 UTC (rev 1464) +++ trunk/gdata/inst/unitTests/runit.nPairs.R 2011-01-15 21:58:56 UTC (rev 1465) @@ -26,11 +26,12 @@ V2=c(NA, 2, 3, 4, 5), V3=c(1, NA, NA, NA, NA), V4=c(1, 2, 3, NA, NA)) - testCheck <- matrix(as.integer(c(5, 4, 1, 3, - 4, 4, 0, 2, - 1, 0, 1, 1, - 3, 2, 1, 3)), + testCheck <- matrix(data=as.integer(c(5, 4, 1, 3, + 4, 4, 0, 2, + 1, 0, 1, 1, + 3, 2, 1, 3)), nrow=4, ncol=4, byrow=TRUE) + class(testCheck) <- c("nPairs", class(testCheck)) testCheckNames <- testCheck colnames(testCheckNames) <- rownames(testCheckNames) <- colnames(test) @@ -41,10 +42,21 @@ checkIdentical(nPairs(x=as.matrix(test), names=FALSE), testCheck) testCheck <- cbind(testCheckNames, as.integer(c(5, 4, 0, 0))) + class(testCheck) <- class(testCheckNames) colnames(testCheck) <- c(colnames(test), "all") checkIdentical(nPairs(x=test, margin=TRUE), testCheck) + + testCheckSumm <- matrix(data=as.integer(c(0, 1, 4, 2, + 0, 0, 4, 2, + 0, 1, 0, 0, + 0, 1, 2, 0)), + nrow=4, ncol=4, byrow=TRUE) + dimnames(testCheckSumm) <- dimnames(testCheckNames) + tmp <- summary(nPairs(x=test)) + checkEquals(tmp, testCheckSumm) } + ### }}} ### {{{ Dear Emacs ### Local variables: Modified: trunk/gdata/man/nPairs.Rd =================================================================== --- trunk/gdata/man/nPairs.Rd 2011-01-06 19:33:26 UTC (rev 1464) +++ trunk/gdata/man/nPairs.Rd 2011-01-15 21:58:56 UTC (rev 1465) @@ -31,6 +31,14 @@ \item{\dots}{other arguments passed to \code{\link{abbreviate}}} } +\details{ + +The class of returned matrix is nPairs and matrix. There is a summary method, +which shows the opposite information - counts how many times each variable is +known, while the other variable of a pair is not. See examples. + +} + \value{ Matrix of order \eqn{k}, where \eqn{k} is the number of columns in \code{x}. @@ -65,6 +73,8 @@ ## Margin nPairs(x=test, margin=TRUE) +## Summary +summary(object=nPairs(x=test)) } \keyword{misc} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2011-04-16 17:04:12
|
Revision: 1469 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1469&view=rev Author: warnes Date: 2011-04-16 17:04:06 +0000 (Sat, 16 Apr 2011) Log Message: ----------- Update for release 2.8.2 Modified Paths: -------------- trunk/gdata/DESCRIPTION trunk/gdata/inst/NEWS Modified: trunk/gdata/DESCRIPTION =================================================================== --- trunk/gdata/DESCRIPTION 2011-04-15 20:25:24 UTC (rev 1468) +++ trunk/gdata/DESCRIPTION 2011-04-16 17:04:06 UTC (rev 1469) @@ -3,8 +3,8 @@ Description: Various R programming tools for data manipulation Depends: R (>= 2.6.0) Imports: gtools -Version: 2.8.1 -Date: 2010-11-12 +Version: 2.8.2 +Date: 2011-04-15 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 Modified: trunk/gdata/inst/NEWS =================================================================== --- trunk/gdata/inst/NEWS 2011-04-15 20:25:24 UTC (rev 1468) +++ trunk/gdata/inst/NEWS 2011-04-16 17:04:06 UTC (rev 1469) @@ -1,5 +1,4 @@ - -CHANGES IN 2.?.? (2011-??-??) +CHANGES IN 2.8.1 (2011-04-15) ----------------------------- Enhancements: @@ -7,6 +6,11 @@ - nPairs() gains a summary method that shows how many times each variable is known, while the other variable of a pair is not +Bug fixes: + +- Fix errors on windows when R or Perl install path includes spaces by properly quoting the path. + + CHANGES IN 2.8.1 (2010-11-12) ----------------------------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |