[R-gregmisc-commits] r2076 - in pkg/gdata: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Feb 5 18:30:08 CET 2016
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}
More information about the R-gregmisc-commits
mailing list