File: runit.trim.R

package info (click to toggle)
gdata 3.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 964 kB
  • sloc: sh: 27; makefile: 15
file content (32 lines) | stat: -rw-r--r-- 919 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
## Test setup
if(FALSE) {
  library("RUnit")
  library("gdata")
}

test.trim <- function()
{
  tmp <- Sys.getlocale(category="LC_COLLATE")
  Sys.setlocale(category="LC_COLLATE", locale="C")

  sTrim <- "    this is an example string    "
  sTrimR <- "this is an example string"

  fTrim <- factor(c(sTrim, sTrim, " A", " B ", "  C ", "D "))
  fTrimR <- factor(c(sTrimR, sTrimR, "A", "B", "C", "D"))

  lTrim <- list(s=rep(sTrim, times=6), f=fTrim, i=1:6)
  lTrimR <- list(s=rep(sTrimR, times=6), f=fTrimR, i=1:6)

  dfTrim <- as.data.frame(lTrim)
  dfTrimR <- as.data.frame(lTrimR)

  checkIdentical(trim(sTrim), sTrimR)
  checkIdentical(trim(fTrim), fTrimR)
  checkIdentical(levels(trim(fTrim, recode.factor=FALSE)),
                 c("this is an example string", "C", "A", "B", "D"))
  checkIdentical(trim(lTrim), lTrimR)
  checkIdentical(trim(dfTrim), dfTrimR)

  Sys.setlocale(category="LC_COLLATE", locale=tmp)
}