-
Notifications
You must be signed in to change notification settings - Fork 8
/
Introspection.R
67 lines (45 loc) · 1.2 KB
/
Introspection.R
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
## THESE ARE A COLLECTION OF INTROSPECTIONS
## ADD TO THIS LIST
## ALSO, CMT(.) SHOULD BE HERE
intr <- introspect <- function(obj) {
ret <- list()
ret[["i.have"]]<- whatHaveI(obj)
ret[["i.am"]] <- whatAmI(obj)
ret[["CMT"]] <- CMT(obj)
ret
}
#----------------------
whatAmI <- function(obj, all=FALSE) {
iam <- c(
list= is.list(obj),
vector= is.vector(obj),
matrix= is.matrix(obj),
array= is.array(obj),
data.frame= is.data.frame(obj),
integer= is.integer(obj),
numeric= is.numeric(obj),
character= is.character(obj),
object= is.object(obj),
# formula= is.formula(obj),
call= is.call(obj),
language= is.language(obj),
symbol= is.symbol(obj),
'function'= is.function(obj),
NULL)
if (!all)
iam <- names(iam[which(iam)])
return(iam)
}
#----------------------
whatHaveI <- function(obj, all=FALSE) {
ihave <- c(
length = !is.null(length(obj)),
dim = !is.null(dim(obj)),
names= !is.null(names(obj)),
colnames= !is.null(colnames(obj)),
rownames= !is.null(rownames(obj)),
NULL)
if (!all)
ihave <- names(ihave[which(ihave)])
return(ihave)
}