The R Project SVN R

Rev

Rev 60323 | Rev 63672 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 60323 Rev 61168
Line 244... Line 244...
244
}
244
}
245
\examples{
245
\examples{
246
grep("[a-z]", letters)
246
grep("[a-z]", letters)
247
 
247
 
248
txt <- c("arm","foot","lefroo", "bafoobar")
248
txt <- c("arm","foot","lefroo", "bafoobar")
249
if(length(i <- grep("foo",txt)))
249
if(length(i <- grep("foo", txt)))
250
   cat("'foo' appears at least once in\n\t",txt,"\n")
250
   cat("'foo' appears at least once in\n\t", txt, "\n")
251
i # 2 and 4
251
i # 2 and 4
252
txt[i]
252
txt[i]
253
 
253
 
254
## Double all 'a' or 'b's;  "\\" must be escaped, i.e., 'doubled'
254
## Double all 'a' or 'b's;  "\\" must be escaped, i.e., 'doubled'
255
gsub("([ab])", "\\\\1_\\\\1_", "abc and ABC")
255
gsub("([ab])", "\\\\1_\\\\1_", "abc and ABC")
Line 288... Line 288...
288
  aa[iw]
288
  aa[iw]
289
}
289
}
290
findArgs("package:base", "warn")
290
findArgs("package:base", "warn")
291
 
291
 
292
## trim trailing white space
292
## trim trailing white space
293
str <- 'Now is the time      '
293
str <- "Now is the time      "
294
sub(' +$', '', str)  ## spaces only
294
sub(" +$", "", str)  ## spaces only
295
sub('[[:space:]]+$', '', str) ## white space, POSIX-style
295
sub("[[:space:]]+$", "", str) ## white space, POSIX-style
296
sub('\\\\s+$', '', str, perl = TRUE) ## Perl-style white space
296
sub("\\\\s+$", "", str, perl = TRUE) ## Perl-style white space
297
 
297
 
298
## capitalizing
298
## capitalizing
299
txt <- "a test of capitalizing"
299
txt <- "a test of capitalizing"
300
gsub("(\\\\w)(\\\\w*)", "\\\\U\\\\1\\\\L\\\\2", txt, perl=TRUE)
300
gsub("(\\\\w)(\\\\w*)", "\\\\U\\\\1\\\\L\\\\2", txt, perl=TRUE)
301
gsub("\\\\b(\\\\w)",    "\\\\U\\\\1",       txt, perl=TRUE)
301
gsub("\\\\b(\\\\w)",    "\\\\U\\\\1",       txt, perl=TRUE)