[R-gregmisc-users] SF.net SVN: r-gregmisc: [989] trunk/gdata
Brought to you by:
warnes
|
From: <gg...@us...> - 2006-10-29 15:28:35
|
Revision: 989
http://svn.sourceforge.net/r-gregmisc/?rev=989&view=rev
Author: ggorjan
Date: 2006-10-29 07:28:26 -0800 (Sun, 29 Oct 2006)
Log Message:
-----------
trim() gains ... argument; version bump
Modified Paths:
--------------
trunk/gdata/DESCRIPTION
trunk/gdata/NEWS
trunk/gdata/R/trim.R
trunk/gdata/man/trim.Rd
Modified: trunk/gdata/DESCRIPTION
===================================================================
--- trunk/gdata/DESCRIPTION 2006-10-29 12:55:08 UTC (rev 988)
+++ trunk/gdata/DESCRIPTION 2006-10-29 15:28:26 UTC (rev 989)
@@ -3,7 +3,7 @@
Description: Various R programming tools for data manipulation
Depends: R (>= 1.9.0)
Imports: gtools
-Version: 2.3.0
+Version: 2.3.1
Author: Gregory R. Warnes. Includes R source code and/or documentation
contributed by Ben Bolker, Gregor Gorjanc, and Thomas Lumley
Maintainer: Gregory Warnes <gre...@ur...>
Modified: trunk/gdata/NEWS
===================================================================
--- trunk/gdata/NEWS 2006-10-29 12:55:08 UTC (rev 988)
+++ trunk/gdata/NEWS 2006-10-29 15:28:26 UTC (rev 989)
@@ -8,6 +8,8 @@
reorder(trt, new.order=c("PLACEBO", "300 MG", "600 MG", "1200 MG"))
+- trim() gains ... argument.
+
CHANGES FROM 2.1.X to 2.3.0 (2006-09-19)
---------------------------------------
Modified: trunk/gdata/R/trim.R
===================================================================
--- trunk/gdata/R/trim.R 2006-10-29 12:55:08 UTC (rev 988)
+++ trunk/gdata/R/trim.R 2006-10-29 15:28:26 UTC (rev 989)
@@ -1,30 +1,34 @@
# $Id$
-trim <- function(s, recode.factor=TRUE)
+trim <- function(s, recode.factor=TRUE, ...)
UseMethod("trim", s)
-trim.default <- function(s, recode.factor=TRUE)
+trim.default <- function(s, recode.factor=TRUE, ...)
s
-trim.character <- function(s, recode.factor=TRUE)
+trim.character <- function(s, recode.factor=TRUE, ...)
{
s <- sub(pattern="^ +", replacement="", x=s)
s <- sub(pattern=" +$", replacement="", x=s)
s
}
-trim.factor <- function(s, recode.factor=TRUE)
+trim.factor <- function(s, recode.factor=TRUE, ...)
{
levels(s) <- trim(levels(s))
- if(recode.factor) s <- reorder.factor(s, sort=sort)
+ if(recode.factor) {
+ dots <- list(x=s, ...)
+ if(is.null(dots$sort)) dots$sort <- sort
+ s <- do.call(what=reorder.factor, args=dots)
+ }
s
}
-trim.list <- function(s, recode.factor=TRUE)
- lapply(s, trim, recode.factor=recode.factor)
+trim.list <- function(s, recode.factor=TRUE, ...)
+ lapply(s, trim, recode.factor=recode.factor, ...)
-trim.data.frame <- function(s, recode.factor=TRUE)
+trim.data.frame <- function(s, recode.factor=TRUE, ...)
{
- s[] <- trim.list(s, recode.factor=recode.factor)
+ s[] <- trim.list(s, recode.factor=recode.factor, ...)
s
}
Modified: trunk/gdata/man/trim.Rd
===================================================================
--- trunk/gdata/man/trim.Rd 2006-10-29 12:55:08 UTC (rev 988)
+++ trunk/gdata/man/trim.Rd 2006-10-29 15:28:26 UTC (rev 989)
@@ -6,11 +6,13 @@
related objects.
}
\usage{
-trim(s, recode.factor=TRUE)
+trim(s, recode.factor=TRUE, \ldots)
}
\arguments{
\item{s}{object to be processed}
- \item{recode.factor}{Should levels of a factor be recoded, see below}
+ \item{recode.factor}{should levels of a factor be recoded, see below}
+ \item{\ldots}{arguments passed to other methods, currently only to
+ \code{\link{reorder.factor}} for factors}
}
\details{
@@ -20,19 +22,22 @@
factor \code{s} trims \code{\link{levels}}. There are also methods for
\code{list} and \code{data.frame}.
-Trimming character strings can change the sort order in some
-locales. For factors, this can affect the coding of levels. By
-default, factor levels are recoded to match the trimmed sort order, but
-this can be disabled by setting \code{recode.factor=FALSE}.
+Trimming character strings can change the sort order in some locales.
+For factors, this can affect the coding of levels. By default, factor
+levels are recoded to match the trimmed sort order, but this can be
+disabled by setting \code{recode.factor=FALSE}. Recoding is done with
+\code{\link{reorder.factor}}.
}
\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{wa...@bs...} 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}}}
+ argument \code{strip.white} in \code{\link{read.table}} and
+ \code{\link{reorder.factor}}
+}
\examples{
s <- " this is an example string "
trim(s)
@@ -43,17 +48,14 @@
trim(f)
levels(trim(f))
-trim(f,recode.factor=FALSE)
-levels(trim(f,recode.factor=FALSE))
+trim(f, recode.factor=FALSE)
+levels(trim(f, recode.factor=FALSE))
-
l <- list(s=rep(s, times=6), f=f, i=1:6)
trim(l)
df <- as.data.frame(l)
trim(df)
-
-
}
\keyword{manip}
\keyword{character}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|