|
5
|
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)
|
|
6
|
13 library(jsonlite)
|
|
5
|
14 #------------------------------------------------
|
|
|
15
|
|
|
16
|
|
|
17 #------------get arguments into R--------------------
|
|
|
18 # load helper function
|
|
|
19 source(paste0(Sys.getenv('TOOL_DIR'), '/helper.R'))
|
|
|
20 # import getopt specification matrix from a csv file
|
|
6
|
21 opt = getopt(getopt_specification_matrix('/search_contents.csv'))
|
|
5
|
22 opt$X_t = Sys.getenv('TOOL_DIR')
|
|
6
|
23 print(opt)
|
|
5
|
24 #----------------------------------------------------
|
|
|
25
|
|
|
26
|
|
6
|
27 #-----------using passed arguments in R
|
|
5
|
28 # to define system environment variables---
|
|
|
29 do.call(Sys.setenv, opt[-1])
|
|
|
30 #----------------------------------------------------
|
|
|
31
|
|
|
32 #---------- often used variables ----------------
|
|
|
33 # OUTPUT_DIR: path to the output associated directory, which stores all outputs
|
|
|
34 # TOOL_DIR: path to the tool installation directory
|
|
|
35 OUTPUT_DIR = opt$X_d
|
|
|
36 TOOL_DIR = opt$X_t
|
|
|
37 OUTPUT_REPORT = opt$X_o
|
|
6
|
38 RMD_NAME = 'search_contents.Rmd'
|
|
5
|
39
|
|
|
40 # create the output associated directory to store all outputs
|
|
|
41 dir.create(OUTPUT_DIR, recursive = TRUE)
|
|
|
42
|
|
|
43 #-----------------render Rmd--------------
|
|
|
44 render(paste0(TOOL_DIR, '/', RMD_NAME), output_file = OUTPUT_REPORT)
|
|
|
45 #------------------------------------------
|
|
|
46
|
|
|
47 #==============the end==============
|
|
|
48
|
|
|
49
|
|
|
50 ##--------end of code rendering .Rmd templates----------------
|
|
|
51 sink()
|
|
6
|
52 ##=========== End of sinking output=============================
|