File: Math.fv.R

package info (click to toggle)
r-cran-spatstat.explore 3.7-0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 3,704 kB
  • sloc: ansic: 4,104; sh: 13; makefile: 5
file content (71 lines) | stat: -rw-r--r-- 1,769 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
##
##   Math.fv.R
##
##   Inline arithmetic for 'fv' 
##
##   $Revision: 1.9 $ $Date: 2023/05/13 01:11:16 $


Math.fv <- function(x, ...){
  force(x)
  eval(substitute(eval.fv(G(x)),
                  list(G=as.name(.Generic),
                       x=quote(x))))
}

Complex.fv <- function(z){
  force(z)
  eval(substitute(eval.fv(G(z)),
                  list(G=as.name(.Generic),
                       z=quote(z))))
}

Ops.fv <- function(e1,e2=NULL) {
  m <- match.call()
  objects <- list()
  if(is.name(m$e1) || (is.atomic(m$e1) && length(m$e1) == 1)) {
    ## e1 is the name of an fv object, or is a single value.
    ## It will appear directly in the resulting function name
    e1use <- substitute(e1)
  } else {
    ## e1 is an expression that should first be evaluated
    ## It will appear as 'e1' in the resulting function name
    e1use <- quote(e1)
    objects$e1 <- eval(e1)
  }
  if(is.name(m$e2) || (is.atomic(m$e2) && length(m$e2) == 1)) {
    e2use <- substitute(e2)
  } else {
    e2use <- quote(e2)
    objects$e2 <- eval(e2)
  }
  callframe <- parent.frame()
  evalframe <-
    if(length(objects)) list2env(objects, parent=callframe) else callframe
  eval(substitute(eval.fv(G(e1,e2),
                          envir=evalframe),
                  list(G=as.name(.Generic),
                       e1=e1use,
                       e2=e2use)))
}

Summary.fv <- local({
  
  Summary.fv <- function(..., na.rm=FALSE){
    argh <- list(...)
    funs <- sapply(argh, is.fv)
    argh[funs] <- lapply(argh[funs], getValues)
    do.call(.Generic, c(argh, list(na.rm = na.rm)))
  }

  getValues <- function(x) {
    xdat <- as.matrix(as.data.frame(x))
    yall <- fvnames(x, ".")
    vals <- xdat[, yall]
    return(as.vector(vals))
  }
  
  Summary.fv
})