-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.R
46 lines (39 loc) · 1015 Bytes
/
template.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
# json library
library('jsonlite')
# wrap all calls in one function to capture output
# this could also be done by calling an external script instead of a function within this one
function_to_call <- function(dataIn) {
sumFunc <- function (num1, num2){
sum(num1, num2)
}
# call function
ret <- sumFunc(as.numeric(dataIn$a),as.numeric(dataIn$b))
# output JSON
print(toJSON(output))
}
run <- function(dataIn) {
# Parse commandline arguments from dataIn
json <- NULL
if (length(dataIn) > 0) {
json <- fromJSON(dataIn)
}
# run script, capture output
captured <- tryCatch(capture.output({
temp <- cluster_sessions(json)
}), error = function(err) err)
# process and return
if (inherits(captured, "error")) {
msg <- conditionMessage(captured)
cat("Error in R script\n", sQuote(msg), file = stderr())
return(invisible(F))
}
out <- if (is.null(temp)) {
""
} else {
temp
}
toJSON(out)
}
suppressWarnings(
run(commandArgs(trailingOnly = TRUE))
)