R/execute_R_prog.R

# 
# 
# .libPaths(c(normalizePath(paste0(main_path,"libs")), .libPaths())) 
# library(tern)
# 
# 
# library(haven) 
# library(rmarkdown)
# library(dplyr)
#  
# #main_path<<-"/home/bceuser/remusatp/General/lopo/"
# #main_path<<-"/opt/bee_tools/shiny/3.5.3/users/remusatp/PrjectTest_B/"
# 
# source(paste0(functionPath,"filters.R"))
# source(paste0(functionPath,"callB_func.R"))
# 
# #show_condition <- function(code) {
# #  tryCatch(code,
# #           error = function(c) "error",
# #           warning = function(c) "warning",
# #           message = function(c) "No error and no Warning"
# #  )
# #}
# 
#  
execute_R_prog <- function (study,s_path,id)  {

  metaOutput<-getOutput(study,s_path,id)

  study<-metaOutput$Study
  Title<-metaOutput$Titles
  Footnote<-metaOutput$Footnotes
  FilterL<-metaOutput$Filters
  progPath<-paste0(main_path,"Studies/",study,"/program/",metaOutput$`Program ID`,".R")
  outputNameLog<-paste0(metaOutput$`Outputs Produced`,".log")
  outputName<-metaOutput$`Outputs Produced`
  logPath<- paste0(main_path,'Studies/',study,'/log/',metaOutput$`Outputs Produced`,".txt")
  outpPath<- paste0(main_path,'Studies/',study,'/output/',metaOutput$`Outputs Produced`,".pdf")
  dataPath<-paste0(main_path,"Studies/",study,"/data/")
  withProgress(message = paste0(outputName," is running") , value = 0, {
    
    incProgress(1/2, detail = paste("", 1))
    #sink(logPath, type="message")
    zz <- file(logPath, open = "wt")
    # sink(zz)
    sink(zz, type = "message")

    try(
      render(paste0(main_path,"outpTemplate.Rmd"),output_file = outpPath,
             params = list(rep_title = Title,
                           rep_footnote = Footnote,
                           rep_program= progPath
             ))
    )
    
    FilterL<<-NULL
    sink(type = "message")
    close(zz)
    
    incProgress(2/2, detail = paste("Ending", 2))
  })
  
  if (file.exists(logPath)) {
    logmessage<-readLines(logPath)
  }
  else {
    logmessage<-"No log"
  }
  
  showModal(modalDialog(
    title = Title,
    
    tags$div(style="word-wrap:break-word;",tags$p(paste(outpPath," has finshed to run"))),
    ## tags$p(paste(outpPath," has finshed to run")),
    tags$p(logmessage),
    
    easyClose = TRUE
  ))
}

# #####################################
# 
kismet303/lopo3000 documentation built on Dec. 15, 2019, 12:31 a.m.