-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcopilot-sdk.R
53 lines (46 loc) · 1.79 KB
/
copilot-sdk.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
library(jsonlite)
source("logger.R")
source("RFunction.R")
inputFileName = "App-Output Workflow_Instance_001__Segment_Data_by_Speed__2022-07-08_09-49-28.rds" #important to set to NULL for movebank-download
outputFileName = "output.rds"
args <- list()
#################################################################
########################### Arguments ###########################
# The data parameter will be added automatically if input data is available
# The name of the field in the vector must be exaclty the same as in the r function signature
# Example:
# rFunction = function(username, password)
# The paramter must look like:
# args[["username"]] = "any-username"
# args[["password"]] = "any-password"
# Add your arguments of your r function here
args[["stats"]] = TRUE
#args[["selName"]] = "nesting"
#args[["trackVar"]] = "trackId" #def
#################################################################
#################################################################
inputData <- NULL
if(!is.null(inputFileName) && inputFileName != "" && file.exists(inputFileName)) {
cat("Loading file from", inputFileName, "\n")
inputData <- readRDS(file = inputFileName)
} else {
cat("Skip loading: no input File", "\n")
}
# Add the data paramter if input data is available
if (!is.null(inputData)) {
args[["data"]] <- inputData
}
result <- tryCatch({
do.call(rFunction, args)
},
error = function(e) { #if in RFunction.R some error are silenced, they come back here and break the app... (?)
print(paste("ERROR: ", e))
stop(e) # re-throw the exception
}
)
if(!is.null(outputFileName) && outputFileName != "" && !is.null(result)) {
cat("Storing file to", outputFileName, "\n")
saveRDS(result, file = outputFileName)
} else {
cat("Skip store result: no output File or result is missing", "\n")
}