comparison collection_list_render.R @ 0:78018b735124 draft

planemo upload for repository https://github.com/statonlab/docker-GRReport/tree/master/my_tools/rmarkdown_collection_builder commit ec13349788ea42e106b5ba3fc1a5095ed755e644-dirty
author mingchen0919
date Mon, 25 Sep 2017 14:28:52 -0400
parents
children 6be61cb4a1d5
comparison
equal deleted inserted replaced
-1:000000000000 0:78018b735124
1 ##======= Handle arguments from command line ========
2 # setup R error handline to go to stderr
3 options(show.error.messages=FALSE,
4 error=function(){
5 cat(geterrmessage(), file=stderr())
6 quit("no", 1, F)
7 })
8
9 # we need that to not crash galaxy with an UTF8 error on German LC settings.
10 loc = Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")
11
12 # suppress warning
13 options(warn = -1)
14
15 options(stringsAsFactors=FALSE, useFancyQuotes=FALSE)
16 args = commandArgs(trailingOnly=TRUE)
17
18 suppressPackageStartupMessages({
19 library(getopt)
20 library(tools)
21 })
22
23 # column 1: the long flag name
24 # column 2: the short flag alias. A SINGLE character string
25 # column 3: argument mask
26 # 0: no argument
27 # 1: argument required
28 # 2: argument is optional
29 # column 4: date type to which the flag's argument shall be cast.
30 # possible values: logical, integer, double, complex, character.
31 ##------- 1. input data ---------------------
32 spec_list=list()
33 spec_list$FILE_LIST = c('file_list', 'l', '1', 'character')
34 spec_list$ECHO = c('echo', 'e', '1', 'character')
35 ##--------2. output report and outputs --------------
36 spec_list$LIST_COLLECTION = c('list_collection', 'o', '1', 'character')
37 spec_list$REPORT = c('report', 'r', '1', 'character')
38 spec_list$OUTPUT_DIR = c('list_collection_dir', 'd', '1', 'character')
39 ##--------3. Rmd templates in the tool directory ----------
40 spec_list$LIST_COLLECTION_RMD = c('list_collection_rmd', 't', '1', 'character')
41
42 spec = t(as.data.frame(spec_list))
43 opt = getopt(spec)
44 ##====== End of arguments handling ==========
45
46 #------ Load libraries ---------
47 library(rmarkdown)
48 library(htmltools)
49
50 #----- 1. create the report directory ------------------------
51 system(paste0('mkdir -p ', opt$list_collection_dir))
52
53 #----- 2. generate Rmd files with Rmd templates --------------
54 # a. templates without placeholder variables:
55 # copy templates from tool directory to the working directory.
56 # b. templates with placeholder variables:
57 # substitute variables with user input values and place them in the working directory.
58
59 #----- 01 list_collection.Rmd -----------------------
60 readLines(opt$list_collection_rmd) %>%
61 (function(x) {
62 gsub('ECHO', opt$echo, x)
63 }) %>%
64 (function(x) {
65 gsub('FILE_LIST', opt$file_list, x)
66 }) %>%
67 (function(x) {
68 gsub('OUTPUT_DIR', opt$list_collection_dir, x)
69 }) %>%
70 (function(x) {
71 fileConn = file('list_collection.Rmd')
72 writeLines(x, con=fileConn)
73 close(fileConn)
74 })
75
76 #------ 3. render all Rmd files --------
77 render('list_collection.Rmd', output_file = opt$list_collection_html)
78
79 #-------4. manipulate outputs -----------------------------