forked from HBPMedical/algorithm-repository
/
main.R
61 lines (52 loc) · 2.55 KB
/
main.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
54
55
56
57
58
59
#'
#' This script computes the linear regression.
#' The data (input parameters: variables, covariables, grouping) are obtained from the local databases using a specific query.
#' This query will be the same for all nodes.
#'
#' #' Environment variables:
#' - Input Parameters:
#' PARAM_query : SQL query producing the dataframe to analyse
#' PARAM_variables : Column separated list of variables, only the first variable will be used
#' PARAM_covariables : Column separated list of covariables
#' PARAM_grouping : Column separated list of groupings
#' - Execution context:
#' JOB_ID : ID of the job
#' NODE : Node used for the execution of the script
#' IN_DBI_DRIVER : Class name of the DBI driver for input data
#' IN_DBI_DBNAME : Database name for the database connection for input data
#' IN_DBI_HOST : Host name for the database connection for input data
#' IN_DBI_PORT : Port number for the database connection for input data
#' IN_DBI_PASSWORD : Password for the database connection for input data
#' IN_DBI_USER : User for the database connection for input data
#' OUT_DBI_DRIVER : Class name of the DBI driver for output data
#' OUT_DBI_DBNAME : Database name for the database connection for output data
#' OUT_DBI_HOST : Host name for the database connection for output data
#' OUT_DBI_PORT : Port number for the database connection for output data
#' OUT_DBI_USER : User for the database connection for output data
#' OUT_DBI_PASSWORD : Password for the database connection for output data
library(rmipadaptor)
library(magrittr)
library(aurelius)
# Initialisation
env_vars_names <- c("PARAM_variables",
"PARAM_covariables",
"PARAM_grouping",
"PARAM_query")
vars_names_r <- substring(text = env_vars_names,first = 7)
vars_list <- env_vars_names %>%
# read the specified variables into a character
Sys.getenv() %>%
# split each string and output a list of character vectors
strsplit(split = ",")
# assign in the global evviroment (or you can use attach(vars_list))
lapply(seq_along(vars_list),
function(x) {
assign(vars_names_r[x], vars_list[[x]], envir=.GlobalEnv)
}
)
docker_image <- Sys.getenv("DOCKER_IMAGE", "hbpmip/r-linear-regression:latest");
data <- fetchData();
formul <- as.formula(paste(variables,"~",paste(covariables, collapse = " + ")))
model <- lm(formula = formul, data = data)
blob <- write_pfa(pfa(model))
saveResults(results = blob,shape = "pfa_json")