[R-gregmisc-users] SF.net SVN: r-gregmisc:[1699] trunk/gtools
Brought to you by:
warnes
|
From: <wa...@us...> - 2013-07-06 23:26:10
|
Revision: 1699
http://sourceforge.net/p/r-gregmisc/code/1699
Author: warnes
Date: 2013-07-06 23:26:07 +0000 (Sat, 06 Jul 2013)
Log Message:
-----------
Create new function lastAdd to replace addLast and mark addLast as deprecated.
Modified Paths:
--------------
trunk/gtools/R/addLast.R
trunk/gtools/man/gtools-deprecated.Rd
Added Paths:
-----------
trunk/gtools/man/addLast-deprecated.Rd
trunk/gtools/man/gtools-defunct.Rd
trunk/gtools/man/lastAdd.Rd
Removed Paths:
-------------
trunk/gtools/man/addLast.Rd
Modified: trunk/gtools/R/addLast.R
===================================================================
--- trunk/gtools/R/addLast.R 2013-07-05 23:48:27 UTC (rev 1698)
+++ trunk/gtools/R/addLast.R 2013-07-06 23:26:07 UTC (rev 1699)
@@ -1,8 +1,30 @@
addLast <- function( fun )
{
+ .Deprecated(new=paste(".Last <- lastAdd(", deparse(substitute(fun)), ")"),
+ package='gtools'
+ )
+
if (!is.function(fun)) stop("fun must be a function")
+ if (!exists(".Last", envir = .GlobalEnv))
+ assign(".Last", fun, envir = .GlobalEnv)
+ else
+ {
+ Last <- get(".Last", envir = .GlobalEnv)
+ newfun <- function(...) {
+ fun()
+ Last()
+ }
+ assign(".Last", newfun, envir = .GlobalEnv)
+ }
+ }
+
+lastAdd <- function( fun )
+ {
+ if (!is.function(fun)) stop("fun must be a function")
if(!exists(".Last", envir=.GlobalEnv))
- assign(".Last", fun, envir=.GlobalEnv)
+ {
+ return(fun)
+ }
else
{
Last <- get(".Last", envir=.GlobalEnv)
@@ -11,6 +33,7 @@
fun()
Last()
}
- assign(".Last", newfun, envir=.GlobalEnv)
+ return(newfun)
}
}
+
Copied: trunk/gtools/man/addLast-deprecated.Rd (from rev 1697, trunk/gtools/man/addLast.Rd)
===================================================================
--- trunk/gtools/man/addLast-deprecated.Rd (rev 0)
+++ trunk/gtools/man/addLast-deprecated.Rd 2013-07-06 23:26:07 UTC (rev 1699)
@@ -0,0 +1,78 @@
+\name{addLast-deprecated}
+\alias{addLast-deprecated}
+\title{Add a function to be executed when R exits.}
+\description{
+ Add a function to be executed when R exits.
+}
+\usage{
+addLast(fun)
+}
+\arguments{
+ \item{fun}{Function to be called.}
+}
+\details{
+ \code{addLast} defines the \code{.Last} function in the global
+ environment (if not already present) or redifines it so that the
+ function \code{fun} will be called when R exits. The latter is
+ accomplished by saving the current definition of \code{.Last} and
+ creating a new \code{.Last} function that calls \code{fun} and then
+ the original \code{.Last} function.
+}
+\value{
+ None.
+}
+\note{This function has been deprecated in favor of \code{lastAdd}
+ because it creates/modifies the definition of '.Last' in the
+ global environment, which is expressly disallowed by the CRAN
+ policies. }
+\author{Gregory R. Warnes \email{gr...@wa...}}
+\seealso{
+ \code{\link[base]{.Last}},
+ \code{\link[gtools]{lastAdd}}
+}
+\examples{
+
+## Print a couple of cute messages when R exits.
+helloWorld <- function() cat("\nHello World!\n")
+byeWorld <- function() cat("\nGoodbye World!\n")
+
+addLast(byeWorld)
+addLast(helloWorld)
+
+\dontrun{
+q("no")
+
+## Should yield:
+##
+## Save workspace image? [y/n/c]: n
+##
+## Hello World!
+##
+## Goodbye World!
+##
+## Process R finished at Tue Nov 22 10:28:55 2005
+}
+
+## Unix-flavour example: send Rplots.ps to printer on exit.
+myLast <- function()
+{
+ cat("Now sending PostScript graphics to the printer:\n")
+ system("lpr Rplots.ps")
+ cat("bye bye...\n")
+}
+addLast(myLast)
+\dontrun{
+quit("yes")
+
+## Should yield:
+##
+## Now sending PostScript graphics to the printer:
+## lpr: job 1341 queued
+## bye bye...
+##
+## Process R finished at Tue Nov 22 10:28:55 2005
+}
+
+}
+\keyword{programming}
+
Deleted: trunk/gtools/man/addLast.Rd
===================================================================
--- trunk/gtools/man/addLast.Rd 2013-07-05 23:48:27 UTC (rev 1698)
+++ trunk/gtools/man/addLast.Rd 2013-07-06 23:26:07 UTC (rev 1699)
@@ -1,73 +0,0 @@
-\name{addLast}
-\alias{addLast}
-\title{Add a function to be executed when R exits.}
-\description{
- Add a function to be executed when R exits.
-}
-\usage{
-addLast(fun)
-}
-\arguments{
- \item{fun}{Function to be called.}
-}
-\details{
- \code{addLast} defines the \code{.Last} function in the global
- environment (if not already present) or redifines it so that the
- function \code{fun} will be called when R exits. The latter is
- accomplished by saving the current definition of \code{.Last} and
- creating a new \code{.Last} function that calls \code{fun} and then
- the original \code{.Last} function.
-}
-\value{
- None.
-}
-\note{This function creates/modifies the definition of '.Last' in the
- global environment.}
-\author{Gregory R. Warnes \email{gr...@wa...}}
-\seealso{ \code{\link[base]{.Last}} }
-\examples{
-
-## Print a couple of cute messages when R exits.
-helloWorld <- function() cat("\nHello World!\n")
-byeWorld <- function() cat("\nGoodbye World!\n")
-
-addLast(byeWorld)
-addLast(helloWorld)
-
-\dontrun{
-q("no")
-
-## Should yield:
-##
-## Save workspace image? [y/n/c]: n
-##
-## Hello World!
-##
-## Goodbye World!
-##
-## Process R finished at Tue Nov 22 10:28:55 2005
-}
-
-## Unix-flavour example: send Rplots.ps to printer on exit.
-myLast <- function()
-{
- cat("Now sending PostScript graphics to the printer:\n")
- system("lpr Rplots.ps")
- cat("bye bye...\n")
-}
-addLast(myLast)
-\dontrun{
-quit("yes")
-
-## Should yield:
-##
-## Now sending PostScript graphics to the printer:
-## lpr: job 1341 queued
-## bye bye...
-##
-## Process R finished at Tue Nov 22 10:28:55 2005
-}
-
-}
-\keyword{programming}
-
Copied: trunk/gtools/man/gtools-defunct.Rd (from rev 1698, trunk/gtools/man/gtools-deprecated.Rd)
===================================================================
--- trunk/gtools/man/gtools-defunct.Rd (rev 0)
+++ trunk/gtools/man/gtools-defunct.Rd 2013-07-06 23:26:07 UTC (rev 1699)
@@ -0,0 +1,20 @@
+\name{gtools-defunct}
+\alias{gtools-defunct}
+\alias{assert}
+\title{Deprecated Functions in the gtools package}
+\description{
+ These functions are no longer available in gtools.
+}
+\usage{
+assert(FLAG)
+}
+\arguments{
+ \item{FLAG}{ Expression that should evaluate to a boolean vector}
+}
+\details{
+ \code{assert} is a defunct synonym for \code{\link[base]{stopifnot}}.
+}
+\seealso{
+ \code{\link{Defunct}}
+}
+\keyword{misc}
Modified: trunk/gtools/man/gtools-deprecated.Rd
===================================================================
--- trunk/gtools/man/gtools-deprecated.Rd 2013-07-05 23:48:27 UTC (rev 1698)
+++ trunk/gtools/man/gtools-deprecated.Rd 2013-07-06 23:26:07 UTC (rev 1699)
@@ -1,24 +1,29 @@
\name{gtools-deprecated}
\alias{gtools-deprecated}
-\alias{assert}
+\alias{addLast}
\title{Deprecated Functions in the gtools package}
\description{
These functions are provided for compatibility with older versions of
gtools, and may be defunct as soon as the next release.
}
\usage{
-assert(FLAG)
+addLast(fun)
}
\arguments{
- \item{FLAG}{ Expression that should evaluate to a boolean vector}
+ \item{fun}{Function to be called.}
}
\details{
The original help page for these functions is often
available at \code{help("oldName-deprecated")} (note the quotes).
- \code{assert} is a deprecated synonym for \code{\link[base]{stopifnot}}.
+ \itemize{
+ \item{ \code{addLast} has been replaced by \code{lastAdd}, which has
+ the same purpose but appled using different syntax. }
+ }
+
}
\seealso{
\code{\link{Deprecated}}
+ \code{\link[gtools]{lastAdd}}
}
\keyword{misc}
Copied: trunk/gtools/man/lastAdd.Rd (from rev 1697, trunk/gtools/man/addLast.Rd)
===================================================================
--- trunk/gtools/man/lastAdd.Rd (rev 0)
+++ trunk/gtools/man/lastAdd.Rd 2013-07-06 23:26:07 UTC (rev 1699)
@@ -0,0 +1,86 @@
+\name{lastAdd}
+\alias{lastAdd}
+\title{Non-destructively construct a .Last function to be executed when R exits.}
+\description{
+ Non-destructively construct a \code{.Last} function to be executed when R exits.
+}
+\usage{
+.Last <- addLast(fun)
+}
+\arguments{
+ \item{fun}{Function to be called.}
+}
+\details{
+ \code{lastAdd} constructs a new function to be used to replace the
+ exising definition of \code{.Last}, which will be executed when R
+ terminates normally.
+
+ If a \code{.Last} function already exists in the global environment,
+ the original definition is stored in a private environment, and the
+ new function is defined to call the function \code{fun} and then to
+ call the previous (stored) definition of \code{.Last}.
+
+ If no \code{.Last} function exists in the global environment,
+ \code{lastAdd} simply returns the function \code{fun}.
+}
+
+\note{
+ This function replaces the (now deprecated) \code{addLast} function.
+}
+\value{
+ A new function to be used for \code{.Last}.
+}
+\author{Gregory R. Warnes \email{gr...@wa...}}
+\seealso{ \code{\link[base]{.Last}} }
+\examples{
+
+## Print a couple of cute messages when R exits.
+helloWorld <- function() cat("\nHello World!\n")
+byeWorld <- function() cat("\nGoodbye World!\n")
+
+.Last <- lastAdd(byeWorld)
+.Last <- lastAdd(helloWorld)
+
+\dontshow{
+.Last()
+}
+\dontrun{
+q("no")
+
+## Should yield:
+##
+## Save workspace image? [y/n/c]: n
+##
+## Hello World!
+##
+## Goodbye World!
+##
+## Process R finished at Tue Nov 22 10:28:55 2005
+}
+
+## Unix-flavour example: send Rplots.ps to printer on exit.
+myLast <- function()
+{
+ cat("Now sending PostScript graphics to the printer:\n")
+ system("lpr Rplots.ps")
+ cat("bye bye...\n")
+}
+.Last <- lastAdd(myLast)
+\dontshow{
+.Last()
+}
+\dontrun{
+quit("yes")
+
+## Should yield:
+##
+## Now sending PostScript graphics to the printer:
+## lpr: job 1341 queued
+## bye bye...
+##
+## Process R finished at Tue Nov 22 10:28:55 2005
+}
+
+}
+\keyword{programming}
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|