Mercurial > repos > koash > test
comparison addTwoNumbers.R @ 3:3d7aaffea9f8 default tip
commit test2
author | ana0gramg+galaxytd@gmail.com |
---|---|
date | Wed, 19 Nov 2014 13:14:01 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
2:df838f5c0c61 | 3:3d7aaffea9f8 |
---|---|
1 #!/usr/bin/env Rscript | |
2 | |
3 ## begin warning handler | |
4 withCallingHandlers({ | |
5 | |
6 library(methods) # Because Rscript does not always do this | |
7 | |
8 options('useFancyQuotes' = FALSE) | |
9 | |
10 suppressPackageStartupMessages(library("optparse")) | |
11 suppressPackageStartupMessages(library("RGalaxy")) | |
12 | |
13 | |
14 option_list <- list() | |
15 | |
16 option_list$number1 <- make_option('--number1', type='numeric') | |
17 option_list$number2 <- make_option('--number2', type='numeric') | |
18 option_list$sum <- make_option('--sum', type='character') | |
19 | |
20 | |
21 opt <- parse_args(OptionParser(option_list=option_list)) | |
22 | |
23 suppressPackageStartupMessages(library(RSclient)) | |
24 | |
25 ## function body not needed here, it is in package | |
26 | |
27 params <- list() | |
28 for(param in names(opt)) | |
29 { | |
30 if (!param == "help") | |
31 params[param] <- opt[param] | |
32 } | |
33 | |
34 setClass("GalaxyRemoteError", contains="character") | |
35 wrappedFunction <- function(f) | |
36 { | |
37 tryCatch(do.call(f, params), | |
38 error=function(e) new("GalaxyRemoteError", conditionMessage(e))) | |
39 } | |
40 | |
41 | |
42 c <- RS.connect(host='localhost', port=6311) | |
43 RS.eval(c, options('useFancyQuotes' = FALSE)) | |
44 RS.eval(c, suppressPackageStartupMessages(library(RGalaxy))) | |
45 RS.assign(c, 'params', params) | |
46 RS.assign(c, 'wrappedFunction', wrappedFunction) | |
47 RS.eval(c, setClass('GalaxyRemoteError', contains='character')) | |
48 res <- RS.eval(c, wrappedFunction(addTwoNumbers)) | |
49 RS.close(c) | |
50 if(is(res, 'GalaxyRemoteError'))RGalaxy::gstop(res) | |
51 | |
52 ## end warning handler | |
53 }, warning = function(w) { | |
54 cat(paste("Warning:", conditionMessage(w), "\n")) | |
55 invokeRestart("muffleWarning") | |
56 }) |