-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.R
92 lines (70 loc) · 2.08 KB
/
util.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# Math 180
# Matthew Bucci
# Utilities
# Dec
dec = function(x) {
eval.parent(substitute(x <- x - 1))
}
# Inc
inc = function(x) {
eval.parent(substitute(x <- x + 1))
}
# Quantative or Qualitative
quant_or_qual = function(x) {
return (ifelse(x=="factor", "qualatative", "quantatative"))
}
# Pretty Print
pp = function(x, type = c("normal","heading")) {
# Defaults
type = match.arg(type)
if(length(type) > 1) {type = "normal"}
top_padding = 0
bottom_padding = 0
# Adjust Formatting per type
if(type == "normal") {
# keep defaults
}
if(type == "heading") {
top_padding = 1
bottom_padding = 0
}
# Print it
while(top_padding > 0) {
cat("\n")
dec(top_padding)
}
# cat can't handle these types
if(class(x) == "data.frame" || class(x) == "matrix" ) {
print(x)
} else if(class(x) == "list") {
print(as.data.frame(x))
} else {
cat(x, "\n")
}
while(bottom_padding > 0) {
cat("\n")
dec(bottom_padding)
}
}
All <- function() {
pp("Running All Problems", type = "heading")
problems = getNamedFunctions(pattern="Problem",check=TRUE)
print(problems)
for(i in 1:length(problems)) {
pp(paste("Running ",problems[i],sep=""), type= "heading")
graphics.off()
eval(parse(text = paste(problems[i], "()",sep="")))
readline(prompt="Press [enter] to continue")
}
}
# Depedendencies - This File Will include it's own depedencies in order to make it extremely portable
### HWUtility.R ###
## This is a set of utility functions that assist in manipulating the namespace of R functions
## Gets all functions in global environment that have the word "problem" in their name
## If you are reading this source code: the ability to change the pattern was intentionally left undocumented in hwhelp()
## Use this feature at your own risk.
getNamedFunctions <- function(pattern="problem",check=TRUE) {
has_target_string <- function(x) grepl(pattern, x)
list_of_names <- Filter(has_target_string, ls(envir=.GlobalEnv)) #get list of function names that match pattern
return(list_of_names)
}