|
7
|
1 ##============ Sink warnings and errors to a file ==============
|
|
|
2 ## use the sink() function to wrap all code within it.
|
|
|
3 ##==============================================================
|
|
|
4 zz = file('warnings_and_errors.txt')
|
|
|
5 sink(zz)
|
|
|
6 sink(zz, type = 'message')
|
|
|
7
|
|
|
8 #------------import libraries--------------------
|
|
|
9 options(stringsAsFactors = FALSE)
|
|
|
10
|
|
|
11 library(getopt)
|
|
|
12 library(rmarkdown)
|
|
|
13 #------------------------------------------------
|
|
|
14
|
|
|
15
|
|
|
16 #------------get arguments into R--------------------
|
|
|
17 # load helper function
|
|
|
18 source(paste0(Sys.getenv('TOOL_DIR'), '/helper.R'))
|
|
|
19 # import getopt specification matrix from a csv file
|
|
|
20 opt = getopt(getopt_specification_matrix('/es_gene_search.csv'))
|
|
|
21 opt$X_t = Sys.getenv('TOOL_DIR')
|
|
|
22 #----------------------------------------------------
|
|
|
23
|
|
|
24
|
|
|
25 #-----------using passed arguments in R
|
|
|
26 # to define system environment variables---
|
|
|
27 do.call(Sys.setenv, opt[-1])
|
|
|
28 #----------------------------------------------------
|
|
|
29
|
|
|
30 #---------- often used variables ----------------
|
|
|
31 # OUTPUT_DIR: path to the output associated directory, which stores all outputs
|
|
|
32 # TOOL_DIR: path to the tool installation directory
|
|
|
33 OUTPUT_DIR = opt$X_d
|
|
|
34 TOOL_DIR = opt$X_t
|
|
|
35 OUTPUT_REPORT = opt$X_o
|
|
|
36 RMD_NAME = 'es_gene_search.Rmd'
|
|
|
37
|
|
|
38 # create the output associated directory to store all outputs
|
|
|
39 dir.create(OUTPUT_DIR, recursive = TRUE)
|
|
|
40
|
|
|
41 #-----------------render Rmd--------------
|
|
|
42 render(paste0(TOOL_DIR, '/', RMD_NAME), output_file = OUTPUT_REPORT)
|
|
|
43 #------------------------------------------
|
|
|
44
|
|
|
45 #==============the end==============
|
|
|
46
|
|
|
47
|
|
|
48 ##--------end of code rendering .Rmd templates----------------
|
|
|
49 sink()
|
|
|
50 ##=========== End of sinking output=============================
|