File: combine.s

package info (click to toggle)
hmisc 3.8-2-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 2,632 kB
  • ctags: 680
  • sloc: asm: 24,359; fortran: 516; ansic: 373; xml: 160; makefile: 1
file content (47 lines) | stat: -rw-r--r-- 1,062 bytes parent folder | download | duplicates (2)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
.ElmtCombine <- function(x, value, protect=FALSE, ...) {
  if(is.null(x)) {
    x <- vector()
  }

  if(is.null(value)) {
    value <- vector()
  }
  
  if((is.list(x) || is.vector(x)) &&
     (is.list(value) || is.vector(value))) {
    if(length(value)) {
      value.names <- names(value)
    } else {
      value.names <- vector()
    }
    
    if(length(x)) {
      x.names <- names(x)
    } else {
      x.names <- vector()
    }

    if(is.null(x.names) || is.null(value.names)) {
      stop("objects 'x' and 'value' must have names")
    }

    if(protect) {
      target <- value
      rep.vals <- x
      rep.names <- x.names
    } else {
      target <- x
      rep.vals <- value
      rep.names <- value.names
    }
        
    target[rep.names] <- rep.vals[rep.names]
    return(target)
  }
  stop("unable to combine these objects")
}

combine <- .ElmtCombine
'combine<-' <- as.function(c(formals(.ElmtCombine)[c('x','protect','...','value')],
                             body(.ElmtCombine)),
                           environment(.ElmtCombine))