[R-gregmisc-users] SF.net SVN: r-gregmisc:[1544] trunk/gdata
Brought to you by:
warnes
From: <wa...@us...> - 2012-06-06 01:53:32
|
Revision: 1544 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1544&view=rev Author: warnes Date: 2012-06-06 01:53:25 +0000 (Wed, 06 Jun 2012) Log Message: ----------- - Add manual page and NAMESPACE entry for startsWith(). - Add 'ignore.case' argument to startsWith(). Modified Paths: -------------- trunk/gdata/NAMESPACE trunk/gdata/R/startsWith.R Added Paths: ----------- trunk/gdata/man/startsWith.Rd Modified: trunk/gdata/NAMESPACE =================================================================== --- trunk/gdata/NAMESPACE 2012-06-06 01:26:07 UTC (rev 1543) +++ trunk/gdata/NAMESPACE 2012-06-06 01:53:25 UTC (rev 1544) @@ -31,6 +31,7 @@ resample, sheetCount, sheetNames, + startsWith, trim, trimSum, unmatrix, Modified: trunk/gdata/R/startsWith.R =================================================================== --- trunk/gdata/R/startsWith.R 2012-06-06 01:26:07 UTC (rev 1543) +++ trunk/gdata/R/startsWith.R 2012-06-06 01:53:25 UTC (rev 1544) @@ -1,5 +1,10 @@ -startsWith <- function(str, pattern, trim=FALSE) +startsWith <- function(str, pattern, trim=FALSE, ignore.case=FALSE) { if(trim) str <- trim(str) + if(ignore.case) + { + str <- toupper(str) + pattern <- toupper(pattern) + } substr(str,start=1,stop=nchar(pattern))==pattern } Added: trunk/gdata/man/startsWith.Rd =================================================================== --- trunk/gdata/man/startsWith.Rd (rev 0) +++ trunk/gdata/man/startsWith.Rd 2012-06-06 01:53:25 UTC (rev 1544) @@ -0,0 +1,48 @@ +\name{startsWith} +\alias{startsWith} +\title{ + Determine if a character string "starts with" with the specified characters. +} +\description{ + Determine if a character string "starts with" with the specified characters. +} +\usage{ +startsWith(str, pattern, trim=FALSE, ignore.case=FALSE) +} +\arguments{ + \item{str}{character vector to test} + \item{pattern}{characters to check for} + \item{trim}{Logical flag indicating whether leading whitespace should + be removed from \code{str} before testing for a match.} + \item{ignore.case}{Logical flag indicating whether case should be + ignored when testing for a match.} +} +\details{ + This function returns TRUE for each element of the vector \code{str} + where \code{pattern} occurs at the beginning of the string. If + \code{trim} is TRUE, leading whitespace is removed from the elements + of \code{str} before the test is performed. If \code{ignore.case} is + TRUE, character case is ignored. +} +\value{ + Boolean vector of the same length as \code{str}. +} +\author{ + Gregory R. Warnes \email{gr...@wa...} +} +\seealso{ + \code{\link[base]{substr}}, \code{\link{trim}} +} +\examples{ +## simplest example: +startsWith( 'Testing', 'Test') + +## vector examples +s <- c('Testing', ' Testing', 'testing', 'Texting') +names(s) <- s + +startsWith(s, 'Test') # ' Testing', 'testing', and 'Texting' do not match +startsWith(s, 'Test', trim=TRUE) # Now ' Testing' matches +startsWith(s, 'Test', ignore.case=TRUE) # Now 'testing' matches +} +\keyword{character} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |