-
Notifications
You must be signed in to change notification settings - Fork 2
/
common.R
81 lines (73 loc) · 2.14 KB
/
common.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
parseArg = function(arg, pattern, msg){
pattern = paste0('^-', pattern, '=')
if(grepl(pattern, arg)){
arg.split = strsplit(arg, '=', fixed = T)[[1]]
if(is.na(arg.split[2])){
stop(paste0('Please specify the value of -', msg))
}else{
return(arg.split[2])
}
}
}
parseArgNum = function(arg, pattern, msg){
pattern = paste0('^-', pattern, '=')
if(grepl(pattern, arg)){
arg.split = strsplit(arg, '=', fixed = T)[[1]]
if(is.na(arg.split[2])){
stop(paste0('Please specify the value of -', msg))
}else{
return(as.numeric(arg.split[2]))
}
}
}
parseArgAsNum = function(arg, pattern, msg){
return(parseArgNum(arg, pattern, msg))
}
parseArgStrs = function(arg, pattern, msg){
pattern = paste0('^-', pattern, '=')
if(grepl(pattern, arg)){
arg.split = strsplit(arg, '=', fixed = T)[[1]]
if(is.na(arg.split[2])){
stop(paste0('Please specify the value of -', msg))
}else{
return(strsplit(arg.split[2], ',', fixed = T)[[1]])
}
}
}
parseArgNums = function(arg, pattern, msg){
pattern = paste0('^-', pattern, '=')
if(grepl(pattern, arg)){
arg.split = strsplit(arg, '=', fixed = T)[[1]]
if(is.na(arg.split[2])){
stop(paste0('Please specify the value of -', msg))
}else{
strs = strsplit(arg.split[2], ',', fixed = T)[[1]]
return(as.numeric(strs))
}
}
}
existNotNull = function(arg){
if(exists(arg) && !is.null(eval(parse(text=arg)))){
return(TRUE)
}else{
return(FALSE)
}
}
outline <- function(df, txt = TRUE){
m <- nrow(df);n <- ncol(df)
plot( c(1,n), c(min(df), max(df)), type = "n", main = "The outline graph of Data", xlab = "Number" , ylab = "Value")
for (i in 1:m){
lines(as.numeric(df[i,]), col=i)
if (txt == TRUE){
k <- dimnames(df)[[1]][i]
text(1+(i-1)%%n, df[i,1+(i-1)%%n], k)
}
}
}
# m=matrix(c(99,94,93,100,100,
# 99,88,96,99,97,
# 100,98,81,96,100), byrow=TRUE,nrow=3
# )
# df=as.data.frame(m)
#
# outline(df,txt=TRUE)