PageRenderTime 33ms CodeModel.GetById 28ms RepoModel.GetById 1ms 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
  1. setClass("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. #setGeneric("show", function(object) standardGeneric("show"))
  20. setMethod("show", "fingerprint",
  21. function(object) {
  22. cat("Fingerprint object\n")
  23. cat(" name = ", object@name, "\n")
  24. cat(" length = ", object@nbit, "\n")
  25. cat(" folded = ", object@folded, "\n")
  26. cat(" source = ", object@provider, "\n")
  27. cat(" bits on = ", paste(sort(object@bits), collapse=' '), "\n")
  28. })
  29. setMethod('as.character', "fingerprint",
  30. function(x) {
  31. s <- numeric(x@nbit)
  32. s[x@bits] <- 1
  33. paste(s,sep='',collapse='')
  34. })
  35. setMethod("length", "fingerprint",
  36. function(x) {
  37. x@nbit
  38. })
  39. parseCall <- function (obj)
  40. {
  41. if (class(obj) != "call") {
  42. stop("Must supply a 'call' object")
  43. }
  44. srep <- deparse(obj)
  45. if (length(srep) > 1)
  46. srep <- paste(srep, sep = "", collapse = "")
  47. fname <- unlist(strsplit(srep, "\\("))[1]
  48. func <- unlist(strsplit(srep, paste(fname, "\\(", sep = "")))[2]
  49. func <- unlist(strsplit(func, ""))
  50. func <- paste(func[-length(func)], sep = "", collapse = "")
  51. func <- unlist(strsplit(func, ","))
  52. vals <- list()
  53. nms <- c()
  54. cnt <- 1
  55. for (args in func) {
  56. arg <- unlist(strsplit(args, "="))[1]
  57. val <- unlist(strsplit(args, "="))[2]
  58. arg <- gsub(" ", "", arg)
  59. val <- gsub(" ", "", val)
  60. vals[[cnt]] <- val
  61. nms[cnt] <- arg
  62. cnt <- cnt + 1
  63. }
  64. names(vals) <- nms
  65. vals
  66. }