[R-gregmisc-users] SF.net SVN: r-gregmisc:[1673] trunk/gplots
Brought to you by:
warnes
From: <wa...@us...> - 2013-06-27 20:20:48
|
Revision: 1673 http://sourceforge.net/p/r-gregmisc/code/1673 Author: warnes Date: 2013-06-27 20:20:46 +0000 (Thu, 27 Jun 2013) Log Message: ----------- Modify sinkplot to use a local environement to store its information instead of the global environment. Modified Paths: -------------- trunk/gplots/R/sinkplot.R trunk/gplots/man/sinkplot.Rd Modified: trunk/gplots/R/sinkplot.R =================================================================== --- trunk/gplots/R/sinkplot.R 2013-06-14 20:58:06 UTC (rev 1672) +++ trunk/gplots/R/sinkplot.R 2013-06-27 20:20:46 UTC (rev 1673) @@ -1,18 +1,19 @@ # $Id$ - +sinkplotEnv <-new.env() + sinkplot <- function(operation=c("start","plot","cancel"),...) { operation <- match.arg(operation) if( operation=="start" ) { - if (exists(".sinkplot.conn", envir=globalenv()) && - get(".sinkplot.conn", envir=globalenv()) ) + if (exists(".sinkplot.conn", envir=sinkplotEnv) && + get(".sinkplot.conn", envir=sinkplotEnv) ) stop("sinkplot already in force") .sinkplot.conn <- textConnection(".sinkplot.data", "w", local=FALSE) - assign(x=".sinkplot.conn", value=.sinkplot.conn, envir=globalenv()) + assign(x=".sinkplot.conn", value=.sinkplot.conn, envir=sinkplotEnv) on.exit(sink()) sink(.sinkplot.conn) @@ -20,23 +21,24 @@ } else { - if (!exists(".sinkplot.conn", envir=globalenv()) || !.sinkplot.conn ) + if (!exists(".sinkplot.conn", envir=sinkplotEnv) || + !get(".sinkplot.conn", envir=sinkplotEnv) ) stop("No sinkplot currently in force") sink() - data <- get(".sinkplot.data", envir=globalenv()) + data <- get(".sinkplot.data", envir=sinkplotEnv) if( operation=="plot" ) textplot( paste( data, collapse="\n"), ... ) - close(get(".sinkplot.conn", envir=globalenv())) + close(get(".sinkplot.conn", envir=sinkplotEnv)) - if(exists(".sinkplot.data", envir=globalenv())) - rm(".sinkplot.data", pos=globalenv()) + if(exists(".sinkplot.data", envir=sinkplotEnv, inherits=FALSE)) + rm(list=".sinkplot.data", pos=sinkplotEnv, inherits=FALSE) - if(exists(".sinkplot.conn", envir=globalenv())) - rm(".sinkplot.conn", pos=globalenv()) + if(exists(".sinkplot.conn", envir=sinkplotEnv, inherits=FALSE)) + rm(list=".sinkplot.conn", pos=sinkplotEnv, inherits=FALSE) invisible(data) } Modified: trunk/gplots/man/sinkplot.Rd =================================================================== --- trunk/gplots/man/sinkplot.Rd 2013-06-14 20:58:06 UTC (rev 1672) +++ trunk/gplots/man/sinkplot.Rd 2013-06-27 20:20:46 UTC (rev 1673) @@ -35,18 +35,18 @@ \author{ Gregory R. Warnes \email{gr...@wa...} } \seealso{ \code{\link[utils]{capture.output}}, \code{\link{textplot}} } \examples{ -\dontrun{ set.seed(12456) x <- factor(sample( LETTERS[1:5], 50, replace=TRUE)) y <- rnorm(50, mean=as.numeric(x), sd=1) + ## construct a figure showing a box plot of the data, followed by an + ## analysis of variance table for the data + layout(cbind(1:2), heights=c(2,1)) - par(mfrow=c(1,2)) boxplot(y~x, col="darkgreen") sinkplot() anova(lm(y~x)) sinkplot("plot",col="darkgreen") } -} \keyword{hplot} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |