diff skewer_render.R @ 4:c7de860e5be7 draft

add jstree
author mingchen0919
date Wed, 18 Apr 2018 10:03:56 -0400
parents d9601e1eb360
children 2c663ddb8488
line wrap: on
line diff
--- a/skewer_render.R	Sun Mar 18 12:29:18 2018 -0400
+++ b/skewer_render.R	Wed Apr 18 10:03:56 2018 -0400
@@ -1,50 +1,43 @@
 ##============ Sink warnings and errors to a file ==============
 ## use the sink() function to wrap all code within it.
 ##==============================================================
-zz = file('warnings_and_errors.txt')
+zz = file(paste0(Sys.getenv('REPORT_FILES_PATH'), '/.r_rendering.log.txt'))
 sink(zz)
 sink(zz, type = 'message')
 
-#------------import libraries--------------------
+#-------------------preparation -----------------
 options(stringsAsFactors = FALSE)
-
+# import libraries
 library(getopt)
 library(rmarkdown)
 library(htmltools)
+# load helper functions
+source(paste0(Sys.getenv('TOOL_INSTALL_DIR'), '/helper.R'))
+# import getopt specification matrix from a csv file
+opt = getopt(getopt_specification_matrix('getopt_specification.csv', 
+                                         tool_dir=Sys.getenv('TOOL_INSTALL_DIR')))
+# define a unix variable versions for all input values. this is useful when we 
+# want to use input values by other programming language in r markdown
+do.call(Sys.setenv, opt[-1])
 #------------------------------------------------
 
 
-#------------get arguments into R--------------------
-# load helper function
-source(paste0(Sys.getenv('TOOL_DIR'), '/helper.R'))
-# import getopt specification matrix from a csv file
-spec_csv = paste0(Sys.getenv('TOOL_DIR'), '/getopt_specification.csv')
-opt = getopt(getopt_specification_matrix(spec_csv))
-opt$X_t = Sys.getenv('TOOL_DIR')
-print(opt)
-#----------------------------------------------------
 
 
-#-----------using passed arguments in R 
-#           to define system environment variables---
-do.call(Sys.setenv, opt[-1])
-#----------------------------------------------------
-
-#---------- often used variables ----------------
-# OUTPUT_DIR: path to the output associated directory, which stores all outputs
-# TOOL_DIR: path to the tool installation directory
-OUTPUT_DIR = opt$X_d
-TOOL_DIR =   opt$X_t
-OUTPUT_REPORT = opt$X_o
-RMD_NAME = 'skewer.Rmd'
-
-# create the output associated directory to store all outputs
-dir.create(OUTPUT_DIR, recursive = TRUE)
-
-#-----------------render Rmd--------------
-render(paste0(TOOL_DIR, '/', RMD_NAME), output_file = OUTPUT_REPORT)
+#-----------------render Rmd files --------------
+# NOTICE: 
+#       we should copy all rmarkdown files from tool install directory to REPORT_FILES_PATH directory.
+#       and render rmarkdown files in the REPORT_FILES_PATH directory.
+file.copy(from = paste0(Sys.getenv('TOOL_INSTALL_DIR'), '/vakata-jstree-3.3.5'),
+          to = Sys.getenv('REPORT_FILES_PATH'), recursive = TRUE)
+system(command = 'cp -r ${TOOL_INSTALL_DIR}/*.Rmd ${REPORT_FILES_PATH}')
+# render Rmd files in order
+render(input = paste0(Sys.getenv('REPORT_FILES_PATH'), '/skewer.Rmd'))
 #------------------------------------------
 
+
+#---------------- copy the output html to REPORT ----
+system(command = 'cp ${REPORT_FILES_PATH}/skewer.html ${REPORT}')
 #==============the end==============