

rm(list=ls())

setwd("C:/Users/victor/Documents/TFG/r-analytics-master")

#Obtain the data from the codebook
codebook <- read.csv("harmon.csv", sep = ";")
codebook <- codebook[,c(1,3,4)]
colnames(codebook) <- c("variable", "description", "unit")

source("dependency_installer.R")
source("connection_parameters_aux.R")
source("necessary_functions_table1_v2_subset.R")

dep_list = c("DSI","DSOpal","DSLite", "dsBaseClient")
install_dependencies(dep_list)

dir.create("./table_1", showWarnings = FALSE)
setwd("./table_1")


#Create the connection
auxConnections <- connect()
connections <- auxConnections[[1]]
inp <- auxConnections[[2]]

#Only do this if you want to subset the data for a specific value of a categoric variable
apply_filters()

#Select the variables to be analized (Add the ones you consider relevant and remove the ones that you do not)
varToAnalize <- c("DMRGENDR","DMRAGEYR","DSXOS", "RFXSM", "TRXAV",  "CMXCVD", "RFXOB")
varToAnalize <- c("DMRGENDR","DMRAGEYR")

table1 <- obtain_table1(connections, inp, varToAnalize)

#datashield.logout(connections)

library(gridExtra)
png("table1TFGFiltro.png", height = 30*nrow(table1), width = 150*ncol(table1))
grid.table(table1)
dev.off()
