-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetopt.R
42 lines (35 loc) · 834 Bytes
/
getopt.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
library(getopt)
spec=matrix(c(
'conf', 'c', 1, "character",
'data', 'd', 1, "character",
'help', 'h', 0, "logical"
),byrow=TRUE,ncol=4);
#command
opt = getopt(spec);
if(is.null(opt$conf)||is.null(opt$data)||is.null(opt$help)){
#err<-"your input was wrong!,please try again!"
#cat(err)
cat("1")
}
#usage<-function(x){
# cat(x)
# q(status=1)
#}
####comment
library(getopt) #loading getopt
#?getopt #get help for getopt
spec = matrix(c(
'help', 'h', 0, 'logical',
'data', 'd', 1, 'integer',
'file', 'f', 1, 'integer' #comma not gived at last row
),byrow=TRUE,ncol=4); #must be semicolon
#command
opt = getopt(spec); #must be semicolon
if(!is.null(opt$conf)||!is.null(opt$data)||!is.null(opt$help)){
err<-"your input was wrong!,please try again!"
usage(err)
}
usage<-function(x){
cat(x)
q(status=1)
}