PageRenderTime 19ms CodeModel.GetById 11ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/fingerprint/R/fingerprint.R

http://github.com/rajarshi/cdkr
R | 71 lines | 65 code | 5 blank | 1 comment | 6 complexity | b1ea2b3bb57e131aa33a2b58ebc8c85a MD5 | raw file
 1setClass("fingerprint",
 2         representation(bits="numeric",
 3                        nbit="numeric",
 4                        folded="logical",
 5                        provider="character",
 6                        name="character",
 7                        misc="list"),
 8         validity=function(object) {
 9           if (any(object@bits > object@nbit))
10             return("Bit positions were greater than the specified bit length")
11           else return(TRUE)           
12         },
13         prototype(bits=c(),
14                   nbit=0,
15                   folded=FALSE,
16                   provider="",
17                   name="",
18                   misc=list()))
19
20#setGeneric("show", function(object) standardGeneric("show"))
21setMethod("show", "fingerprint",
22          function(object) {
23            cat("Fingerprint object\n")
24            cat(" name = ", object@name, "\n")
25            cat(" length = ", object@nbit, "\n")
26            cat(" folded = ", object@folded, "\n")
27            cat(" source = ", object@provider, "\n")
28            cat(" bits on = ", paste(sort(object@bits), collapse=' '), "\n")
29          })
30
31
32setMethod('as.character', "fingerprint",
33          function(x) {
34            s <- numeric(x@nbit)
35            s[x@bits] <- 1
36            paste(s,sep='',collapse='')
37          })
38
39setMethod("length", "fingerprint",
40          function(x) {
41            x@nbit
42          })
43
44parseCall <- function (obj) 
45{
46    if (class(obj) != "call") {
47        stop("Must supply a 'call' object")
48    }
49    srep <- deparse(obj)
50    if (length(srep) > 1) 
51        srep <- paste(srep, sep = "", collapse = "")
52    fname <- unlist(strsplit(srep, "\\("))[1]
53    func <- unlist(strsplit(srep, paste(fname, "\\(", sep = "")))[2]
54    func <- unlist(strsplit(func, ""))
55    func <- paste(func[-length(func)], sep = "", collapse = "")
56    func <- unlist(strsplit(func, ","))
57    vals <- list()
58    nms <- c()
59    cnt <- 1
60    for (args in func) {
61        arg <- unlist(strsplit(args, "="))[1]
62        val <- unlist(strsplit(args, "="))[2]
63        arg <- gsub(" ", "", arg)
64        val <- gsub(" ", "", val)
65        vals[[cnt]] <- val
66        nms[cnt] <- arg
67        cnt <- cnt + 1
68    }
69    names(vals) <- nms
70    vals
71}