0
|
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 # library(dplyr)
|
|
18 # getopt_specification_matrix(extract_short_flags('')) %>%
|
|
19 # write.table(file = 'spec.txt', sep = ',', row.names = FALSE, col.names = TRUE, quote = FALSE)
|
|
20
|
|
21
|
|
22 spec_matrix = as.matrix()
|
|
23 opt = getopt(spec_matrix)
|
|
24 #----------------------------------------------------
|
|
25
|
|
26
|
|
27 #-----------using passed arguments in R
|
|
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 = ''
|
|
36 TOOL_DIR = ''
|
|
37 RMD_NAME = ''
|
|
38 OUTPUT_REPORT = opt$X_o
|
|
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, sep = '/'), output_file = OUTPUT_REPORT)
|
|
45 #------------------------------------------
|
|
46
|
|
47 #==============the end==============
|
|
48
|
|
49
|
|
50 ##--------end of code rendering .Rmd templates----------------
|
|
51 sink()
|
|
52 ##=========== End of sinking output============================= |