From noreply at r-forge.r-project.org Wed Feb 3 21:00:58 2016 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 3 Feb 2016 21:00:58 +0100 (CET) Subject: [R-gregmisc-commits] r2072 - pkg/gdata/R Message-ID: <20160203200058.86F78187D2D@r-forge.r-project.org> Author: warnes Date: 2016-02-03 21:00:57 +0100 (Wed, 03 Feb 2016) New Revision: 2072 Modified: pkg/gdata/R/rename.vars.R Log: Improve logging and error reporting for remove.vars() Modified: pkg/gdata/R/rename.vars.R =================================================================== --- pkg/gdata/R/rename.vars.R 2015-11-24 17:58:02 UTC (rev 2071) +++ pkg/gdata/R/rename.vars.R 2016-02-03 20:00:57 UTC (rev 2072) @@ -44,14 +44,20 @@ } -# GRW 2004-04-01 remove.vars <- function( data, names, info=TRUE) +{ + dsn <- deparse(substitute(data)) + if (info) cat('\nChanging in',dsn, "\n") + + + flag <- names %in% colnames(data) + if(any(!flag)) + warning("Variable(s) not found: ", paste(names[!flag], collapse=", ") ) + if(any(flag)) { - for( i in names ) - { - if(info) - cat("Removing variable '", i, "'\n", sep="") - data[[i]] <- NULL - } - data + if(info) cat("Dropping variables:", paste(names[flag], collapse=", "), "\n\n") + for(var in names[flag]) + data[[var]] <- NULL } + data +} \ No newline at end of file From noreply at r-forge.r-project.org Wed Feb 3 21:13:50 2016 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 3 Feb 2016 21:13:50 +0100 (CET) Subject: [R-gregmisc-commits] r2073 - in pkg/gdata: R man Message-ID: <20160203201350.6DD80186BFF@r-forge.r-project.org> Author: warnes Date: 2016-02-03 21:13:49 +0100 (Wed, 03 Feb 2016) New Revision: 2073 Modified: pkg/gdata/R/first.R pkg/gdata/man/first.Rd Log: Add assignment versions of first() and last() Modified: pkg/gdata/R/first.R =================================================================== --- pkg/gdata/R/first.R 2016-02-03 20:00:57 UTC (rev 2072) +++ pkg/gdata/R/first.R 2016-02-03 20:13:49 UTC (rev 2073) @@ -1,3 +1,16 @@ # Simply call 'first' or 'last' with a different default value for 'n'. first <- function(x, n=1, ...) head(x, n=n, ...) last <- function(x, n=1, ...) tail(x, n=n, ...) + +"first<-" <- function(x, n=1, ..., value ) +{ + x[1:n] <- value[1:n] + x +} + +"last<-" <- function(x, n=1, ..., value ) +{ + index <- seq( length(x)-n+1, length(x) ) + x[index] <- value[1:n] + x +} Modified: pkg/gdata/man/first.Rd =================================================================== --- pkg/gdata/man/first.Rd 2016-02-03 20:00:57 UTC (rev 2072) +++ pkg/gdata/man/first.Rd 2016-02-03 20:13:49 UTC (rev 2073) @@ -1,6 +1,8 @@ \name{first} \alias{first} \alias{last} +\alias{first<-} +\alias{last<-} \title{Return first or last element of an object} \description{ Return first or last element of an object. These functions are convenience @@ -9,6 +11,8 @@ \usage{ first(x, n=1, ...) last(x, n=1, ...) +first(x, n=1, ...) <- value +last(x, n=1, ...) <- value } \arguments{ \item{x}{data object} @@ -17,6 +21,7 @@ matrix or data frame or lines for a function. If negative, all but the 'n' last/first number of elements of 'x'.} \item{...}{arguments to be passed to or from other methods.} + \item{value}{a vector of values to be assigned (should be of length \code{n})} } \value{ An object (usually) like 'x' but generally smaller. @@ -36,20 +41,37 @@ first(v) last(v) +first(v) <- 9 +v + +last(v) <- 20 +v + ## and for lists l <- list(a=1, b=2, c=3) first(l) last(l) +first(l) <- "apple" +last(l) <- "bannana" +l + ## and data.frames df <- data.frame(a=1:2, b=3:4, c=5:6) first(df) last(df) +first(df) <- factor(c("red","green")) +last(df) <- list(c(20,30)) # note the enclosing list! +df + ## and matrixes m <- as.matrix(df) first(m) last(m) +first(m) <- "z" +last(m) <- "q" +m } \keyword{ manip } From noreply at r-forge.r-project.org Wed Feb 3 21:15:02 2016 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 3 Feb 2016 21:15:02 +0100 (CET) Subject: [R-gregmisc-commits] r2074 - in pkg/gdata: R man Message-ID: <20160203201502.6D213186DFC@r-forge.r-project.org> Author: warnes Date: 2016-02-03 21:15:02 +0100 (Wed, 03 Feb 2016) New Revision: 2074 Added: pkg/gdata/R/update.data.frame.R pkg/gdata/R/update.list.R pkg/gdata/man/update.list.Rd Log: Add update() methods for lists and data frames Added: pkg/gdata/R/update.data.frame.R =================================================================== --- pkg/gdata/R/update.data.frame.R (rev 0) +++ pkg/gdata/R/update.data.frame.R 2016-02-03 20:15:02 UTC (rev 2074) @@ -0,0 +1,33 @@ +# This function replace rows in 'x' by corresponding rows in 'y' the have +# the same value for 'by' +update.data.frame <- function(x, y, by, by.x=by, by.y=by, append=TRUE, verbose=TRUE, ...) +{ + retval <- x + x.by <- x[[by.x]] + y.by <- y[[by.y]] + + matches.x <- match(y.by, x.by) + matches.y <- which(!is.na(matches.x)) + nomatch.y <- which(is.na(matches.x)) + matches.x <- matches.x[!is.na(matches.x)] + + if(length(matches.x)>0) + retval[matches.x, ] <- y[matches.y,] + + if(length(nomatch.y) && append) + retval <- rbind(retval, y[nomatch.y,]) + + if(verbose) + { + cat("\n") + cat("Number of rows in x :", nrow(x), "\n") + cat("Number of rows in y :", nrow(y), "\n") + cat("\n") + cat("Number of rows replaced :", length(matches.x), "\n") + cat("Number of rows appended :", length(nomatch.y), "\n") + cat("\n") + cat("Number of rows in result:", nrow(retval), "\n") + cat("\n") + } + retval +} Added: pkg/gdata/R/update.list.R =================================================================== --- pkg/gdata/R/update.list.R (rev 0) +++ pkg/gdata/R/update.list.R 2016-02-03 20:15:02 UTC (rev 2074) @@ -0,0 +1,20 @@ +## this function updates the elements of list 'object' to contain all of the elements +## of 'new', overwriting elements with the same name, and (optionally) copying unnamed +## elements. +update.list <- function(object, new, unnamed=FALSE, ...) +{ + retval <- object + + for(name in names(new)) + retval[[name]] <- new[[name]] + + if(unnamed) + { + if(is.null(names(new))) + names(new) <- rep("", length=length(new)) + for(i in (1:length(new))[names(new)==""] ) + retval <- append(retval, new[[i]]) + } + + retval +} \ No newline at end of file Added: pkg/gdata/man/update.list.Rd =================================================================== --- pkg/gdata/man/update.list.Rd (rev 0) +++ pkg/gdata/man/update.list.Rd 2016-02-03 20:15:02 UTC (rev 2074) @@ -0,0 +1,45 @@ +\name{update.list} +\alias{update.list} +\title{ + Update the elements of a list +} +\description{ + Function to update the elements of a list to contain all of the named elements + of a new list, overwriting elements with the same name, and (optionally) copying unnamed + elements. + } +\usage{ +update.list(object, new, unnamed=FALSE, ...) +\method{update}{list}(object, new, unnamed=FALSE, ...) +} +\arguments{ + \item{object}{List to be updated.} + \item{new}{List containing new elements.} + \item{unnamed}{Logical. If \code{TRUE}, unnamed elements of \code{new} will be appended to \code{object}} +} +\note{ + This method can be called directly, or as via the S3 base method for \code{update}. +} +\value{ +A constructed from the elements of \code{object}, with named elements of \code{new} replacing corresponding named elements from \code{object}, and non-corresponding elements of \code{new} appended. If \code{unnamed=TRUE}, unnamed elements of \code{new} will be appended. +} +\author{ +Gregory R. Warnes \email{greg at warnes.net} +} +\seealso{ +\code{\link[stats]{update}}, \code{\link[base]{merge}} +} +\examples{ +old <- list(a=1,b="red",c=1.37) +new <- list(b="green",c=2.4) + +update(old, new) +update.list(old,new) # equivalent + +older <- list(a=0, b="orange", 4, 5, 6) +newer <- list(b="purple", 7, 8, 9) +update(older, newer) # ignores unnamed elements of newer +update(older, newer, unnamed=TRUE) # appends unnamed elements of newer +} +\keyword{data} +\keyword{manip} From noreply at r-forge.r-project.org Wed Feb 3 21:17:22 2016 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 3 Feb 2016 21:17:22 +0100 (CET) Subject: [R-gregmisc-commits] r2075 - pkg/gdata Message-ID: <20160203201722.40C4C186DFC@r-forge.r-project.org> Author: warnes Date: 2016-02-03 21:17:21 +0100 (Wed, 03 Feb 2016) New Revision: 2075 Modified: pkg/gdata/NAMESPACE Log: - Add update() methods list and data.frame - Add 'first<-' and 'last<-' assignment methods Modified: pkg/gdata/NAMESPACE =================================================================== --- pkg/gdata/NAMESPACE 2016-02-03 20:15:02 UTC (rev 2074) +++ pkg/gdata/NAMESPACE 2016-02-03 20:17:21 UTC (rev 2075) @@ -14,12 +14,14 @@ elem, env, first, + 'first<-', frameApply, installXLSXsupport, interleave, is.what, keep, last, + 'last<-', left, ll, ls.funs, @@ -40,6 +42,8 @@ trim, trimSum, unmatrix, + update.list, + update.data.frame, upperTriangle, "upperTriangle<-", wideByFactor, @@ -164,4 +168,6 @@ S3method(right, data.frame) S3method(right, matrix) - +# update methods for list, data.frame +S3method(update, list) +S3method(update, data.frame) From noreply at r-forge.r-project.org Fri Feb 5 18:30:08 2016 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 5 Feb 2016 18:30:08 +0100 (CET) Subject: [R-gregmisc-commits] r2076 - in pkg/gdata: R man Message-ID: <20160205173008.BD623187D4D@r-forge.r-project.org> Author: warnes Date: 2016-02-05 18:30:08 +0100 (Fri, 05 Feb 2016) New Revision: 2076 Added: pkg/gdata/R/mv.R pkg/gdata/man/mv.Rd Log: Add mv() function to rename an object. Added: pkg/gdata/R/mv.R =================================================================== --- pkg/gdata/R/mv.R (rev 0) +++ pkg/gdata/R/mv.R 2016-02-05 17:30:08 UTC (rev 2076) @@ -0,0 +1,10 @@ +mv <- function(from, to, envir=parent.frame()) +{ + if( !is.character(from) || !exists(from, envir=envir, inherits = TRUE) ) + stop("`from` must be a character string specifying the name of an object.") + if( !is.character(to) ) + stop("`to` must be a characater string.") + value <- get(from, envir=envir) + assign(x=to, value=value, envir=envir) + rm(list=from, envir=envir) +} \ No newline at end of file Added: pkg/gdata/man/mv.Rd =================================================================== --- pkg/gdata/man/mv.Rd (rev 0) +++ pkg/gdata/man/mv.Rd 2016-02-05 17:30:08 UTC (rev 2076) @@ -0,0 +1,37 @@ +\name{mv} +\alias{mv} +\title{ + Rename an Object +} +\description{ + Rename an object. +} +\usage{ +mv(from, to, envir = parent.frame()) +} +\arguments{ + \item{from}{Character scalar giving the source object name} + \item{to}{Character scalar giving the desination object name} + \item{envir}{Environment in which to do the rename} +} +\details{ + This function renames an object by the value of object \code{a} to the name \code{b}, and removing \code{a}. +} +\value{ + Invisibly returns the value of the object. +} +\author{ + Gregory R. Warnes \email{greg at warnes.net} +} +\seealso{ + \code{\link[base]{rm}}, \code{\link[base]{assign}} +} +\examples{ + a <- 1:10 + a + mv("a", "b") + b + exists("a") +} +\keyword{environment} +\keyword{data} From noreply at r-forge.r-project.org Fri Feb 5 18:30:41 2016 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 5 Feb 2016 18:30:41 +0100 (CET) Subject: [R-gregmisc-commits] r2077 - pkg/gdata/man Message-ID: <20160205173041.BD98F187D4D@r-forge.r-project.org> Author: warnes Date: 2016-02-05 18:30:41 +0100 (Fri, 05 Feb 2016) New Revision: 2077 Modified: pkg/gdata/man/update.list.Rd Log: Add documentation for update() data.frame method. Modified: pkg/gdata/man/update.list.Rd =================================================================== --- pkg/gdata/man/update.list.Rd 2016-02-05 17:30:08 UTC (rev 2076) +++ pkg/gdata/man/update.list.Rd 2016-02-05 17:30:41 UTC (rev 2077) @@ -1,5 +1,6 @@ \name{update.list} \alias{update.list} +\alias{update.data.frame} \title{ Update the elements of a list } @@ -11,11 +12,13 @@ \usage{ update.list(object, new, unnamed=FALSE, ...) \method{update}{list}(object, new, unnamed=FALSE, ...) +\method{update}{data.frame}(object, new, unnamed=FALSE, ...) } \arguments{ \item{object}{List to be updated.} \item{new}{List containing new elements.} \item{unnamed}{Logical. If \code{TRUE}, unnamed elements of \code{new} will be appended to \code{object}} + \item{...}{optional method arguments (ignored)} } \note{ This method can be called directly, or as via the S3 base method for \code{update}. From noreply at r-forge.r-project.org Fri Feb 26 20:58:25 2016 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 26 Feb 2016 20:58:25 +0100 (CET) Subject: [R-gregmisc-commits] r2078 - pkg/gplots/R Message-ID: <20160226195825.1A985187331@r-forge.r-project.org> Author: warnes Date: 2016-02-26 20:58:24 +0100 (Fri, 26 Feb 2016) New Revision: 2078 Modified: pkg/gplots/R/heatmap.2.R Log: - heatmap.2() can now be used to plot subsets of a previous heatmap. - Remove stray 'browser()' debuggint statement from heatmap.2() code. - Decrease the granularity of the carpet in heatmap.2()'s color key to avoid visual artifacts. Modified: pkg/gplots/R/heatmap.2.R =================================================================== --- pkg/gplots/R/heatmap.2.R 2016-02-05 17:30:41 UTC (rev 2077) +++ pkg/gplots/R/heatmap.2.R 2016-02-26 19:58:24 UTC (rev 2078) @@ -225,6 +225,7 @@ stop("row dendrogram ordering gave index of wrong length") } else { rowInd <- nr:1 + ddr <- as.dendrogram(Rowv) } ## if( dendrogram %in% c("both","column") ) @@ -273,6 +274,7 @@ else { colInd <- 1:nc + ddc <- as.dendrogram(Colv) } retval$rowInd <- rowInd @@ -627,7 +629,6 @@ if(!is.null(main)) title(main, cex.main = 1.5*op[["cex.main"]]) ## Add the color-key - browser() if(key) { mar <- c(5, 4, 2, 1) @@ -655,7 +656,7 @@ max.raw <- max.breaks } - z <- seq(min.raw, max.raw, by=min(diff(breaks)/4)) + z <- seq(min.raw, max.raw, by=min(diff(breaks)/100)) image(z=matrix(z, ncol=1), col=col, breaks=tmpbreaks, xaxt="n", yaxt="n") From noreply at r-forge.r-project.org Fri Feb 26 20:59:52 2016 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 26 Feb 2016 20:59:52 +0100 (CET) Subject: [R-gregmisc-commits] r2079 - in pkg/gplots: R man Message-ID: <20160226195952.7D951187361@r-forge.r-project.org> Author: warnes Date: 2016-02-26 20:59:52 +0100 (Fri, 26 Feb 2016) New Revision: 2079 Added: pkg/gplots/R/angleAxis.R pkg/gplots/man/angleAxis.Rd Log: New angleAxis() function to create axis labels with rotated text. Added: pkg/gplots/R/angleAxis.R =================================================================== --- pkg/gplots/R/angleAxis.R (rev 0) +++ pkg/gplots/R/angleAxis.R 2016-02-26 19:59:52 UTC (rev 2079) @@ -0,0 +1,22 @@ +angleAxis <- function(side, labels, at=1:length(labels), srt=45, adj, xpd=TRUE, ...) +{ + usr <- par("usr") + emH <- strheight("M") + emW <- strwidth("M") + + if(missing(adj)) + adj <- switch(side, 1, 1, 0, 0) + + switch(side, + #1 - below + text(x=at, y=usr[3]-emH/2, labels=labels, srt=srt, adj=adj, xpd=xpd, ...), + #2 - left + text(x=usr[1]-emW/2, y=at, labels=labels, srt=srt, adj=adj, xpd=xpd, ...), + #3 - above + text(x=at, y=usr[4]+emH/2, labels=labels, srt=srt, adj=adj, xpd=xpd, ...), + #4 - right + text(x=usr[2]+emW/2, y=at, labels=labels, srt=srt, adj=adj, xpd=xpd, ...) + ) + + invisible(NULL) +} \ No newline at end of file Added: pkg/gplots/man/angleAxis.Rd =================================================================== --- pkg/gplots/man/angleAxis.Rd (rev 0) +++ pkg/gplots/man/angleAxis.Rd 2016-02-26 19:59:52 UTC (rev 2079) @@ -0,0 +1,90 @@ +\name{angleAxis} +\alias{angleAxis} +\title{Add a Axis to a Plot with Rotated Labels} +\description{ +Add a labeled axis to the current plot with rotated text +} +\usage{ +angleAxis(side, labels, at = 1:length(labels), srt = 45, adj, xpd = TRUE, ...) +} +\arguments{ + \item{side}{ + an integer specifying which side of the plot the axis is to be + drawn on. The axis is placed as follows: 1=below, 2=left, 3=above and + 4=right. + } + \item{labels}{character or expression vector of labels to be placed at the + tickpoints. + } + \item{at}{the points at which tick-marks are to be drawn. Non-finite + (infinite, NaN or NA) values are omitted. + } + \item{srt}{ + The string rotation in degrees. Defaults to 45 degrees (clockwise). + } + \item{adj}{Text justification. + A value of 0 produces left-justified text, 0.5 centered text and 1 + right-justified text. For \code{side=1} and \code{side=2}, the + default value is \code{adj=1}. For \code{side=3} and \code{side=4} + the default value is \code{adj=0}. + } + \item{xpd}{A logical value or NA. If FALSE, labels are clipped to the + plot region, if TRUE, labels are clipped to the figure region, and + if NA, labels are clipped to the device region. + } + \item{\dots}{optional arguments passed to \code{text}. Common examples are \code{col}, \code{cex}.} +} +\details{ +This function augments the feature of the \code{axis} functon by allowing the axis labels to be rotated. +} +\author{Gregory R. Warnes \email{greg at warnes.net} } +\seealso{ +\code{\link{axis}} +} +\examples{ +\dontshow{set.seed(42)} +# create a vector with some values and long labels +values <- sample(1:10) +names(values) <- sapply(letters[1:10], + function(x) paste(rep(x, 10), sep="",collapse="") + ) + +# barplot labels are too long for the available space, hence some are not plotted +barplot(values) + +# to add angled labels, tell barplot not to label the x axis, and store the bar location +at <- barplot(values, xaxt="n") +# then use angleAxs +angleAxis(1, at=at, labels = names(values)) + +# angle counter-clockwise instead +at <- barplot(values, xaxt="n") +angleAxis(1, at=at, labels = names(values), srt=-45, adj=0) + +# put labels at the top +oldpar <- par()$mar +par(mar=c(1,4,5,2)+0.1) +at <- barplot(values, xaxt="n") +angleAxis(3, at=at, labels = names(values)) +par(oldpar) + +# put labels on the left +oldpar <- par()$mar +par(mar=c(5,5,3,2)+0.1) +at <- barplot(values, yaxt="n", horiz=TRUE) +angleAxis(2, at=at, labels = names(values)) +par(oldpar) + +# put labels on the right +oldpar <- par()$mar +par(mar=c(2,5,3,5)+0.1) +at <- barplot(values, yaxt="n", horiz=TRUE) +angleAxis(4, at=at, labels = names(values)) +par(oldpar) + +# specify colors for bars and labels +at <- barplot(values, xaxt="n", col=1:10) +angleAxis(1, at=at, labels = names(values), col=1:10) +} +\keyword{aplot} + From noreply at r-forge.r-project.org Fri Feb 26 21:00:37 2016 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 26 Feb 2016 21:00:37 +0100 (CET) Subject: [R-gregmisc-commits] r2080 - pkg/gplots/R Message-ID: <20160226200037.3AE9B187361@r-forge.r-project.org> Author: warnes Date: 2016-02-26 21:00:36 +0100 (Fri, 26 Feb 2016) New Revision: 2080 Modified: pkg/gplots/R/venn.R Log: venn() now support matrix arguments. Modified: pkg/gplots/R/venn.R =================================================================== --- pkg/gplots/R/venn.R 2016-02-26 19:59:52 UTC (rev 2079) +++ pkg/gplots/R/venn.R 2016-02-26 20:00:36 UTC (rev 2080) @@ -26,6 +26,11 @@ getVennCounts.list(l, universe=universe, verbose=verbose) } +getVennCounts.matrix <- function(l, universe=NA, verbose=F, ...) +{ + getVennCounts.data.frame(as.data.frame(l), universe=NA, verbose=F, ...) +} + # l offers a list of arrays, their values are to # be tested for the size of their intersects. getVennCounts.list<-function(l, universe=NA, verbose=F, intersections=TRUE) {