-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_gamblr_function.R
executable file
·41 lines (31 loc) · 1.21 KB
/
run_gamblr_function.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
#!/usr/bin/env Rscript
## the line below is only needed for a Mac installation
#!/usr/local/bin/Rscript
library(argparse)
library(readr)
library(GAMBLR)
parser <- ArgumentParser(description= 'This progrom runs a GAMBLR function with arguments specified with --args argname=argvalue')
parser$add_argument('--function_name', '-f', help= 'A valid GAMBLR function name')
parser$add_argument('--args', '-a', help= 'One or more arguments in format argname=argvalue', type= 'character', nargs='+')
xargs<- parser$parse_args()
FUNCTION <- xargs$function_name
ARGS <- xargs$args #argname = argvalue
get_args = function(all_args){
arg_split = list()
for(arg in all_args){
pieces = unlist(strsplit(arg,"="))
arg_split[[pieces[1]]]=pieces[2]
}
return(arg_split)
}
arglist = get_args(ARGS)
available_args = names(formals(FUNCTION))
#check if our function handles the parameters given
if(any(! names(arglist) %in% available_args)){
bad_arg = names(arglist)[which(!names(arglist) %in% available_args)]
stop(paste("ERROR:",bad_arg,"not in available arguments for",FUNCTION))
}
message(paste("FUNCTION:",FUNCTION))
message(paste("ARGS:",arglist))
output = do.call(FUNCTION,arglist)
cat(format_tsv(output))