-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
104 lines (79 loc) · 3.03 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# VARIABLE DEFINITIONS #######################################################
###############################################################################
# folders #####################################################################
DIR:= .#
CODE:= $(DIR)/code
DATA:= $(DIR)/data
FIG:= $(DIR)/figures
DT/P:= $(DATA)/processed
DT/R:= $(DATA)/raw
DT/I:= $(DATA)/interim
DOC:= $(DIR)/docs
JRN:= $(DOC)/journals
RPRT:= $(DOC)/reports
# FILES #######################################################################
# all interim data filee
DT/I/.rds := $(DT/I)/*.rds
# all processed files
DT/P/.rds := $(DT/P)/*.rds
# all figure files
FIGZ := $(FIG)/*.*
# COMMANDS ####################################################################
# recipe to make .dot file of this makefile
define make2dot
@echo creating the .dot file from the dependencies in this makefile ----------
python $(DIR)/code/makefile2dot.py < $< > $@
sed -i 's/rankdir="BT"/rankdir="TB"/' $(DT/P)/make.dot
@echo done -------------------------------------------------------------------
endef
# recipe to make .png file from the dot file
define dot2png
@echo Creating the .png from the .dot ----------------------------------------
dot -Tpng $< -o$(FIG)/make.png
@echo done -------------------------------------------------------------------
endef
# recipe to knit pdf from first prerequisite
define rmd2pdf
@echo creating the $(@F) file by knitting it in R. ---------------------------
Rscript -e "suppressWarnings(suppressMessages(require(rmarkdown)));\
render('$<', output_dir = '$(@D)', output_format = 'pdf_document',\
quiet = TRUE )"
-rm $(wildcard $(@D)/tex2pdf*) -fr
endef
# recipe to knit html from first prerequisite
define rmd2html
@echo creating the $(@F) file by knitting it in R.---------------------------
Rscript -e "suppressWarnings(suppressMessages(require(rmarkdown))); \
render('$<', output_dir = '$(@D)', output_format = 'html_document',\
quiet = TRUE )"
endef
# recipe for sourcing the prerequisite R file
define sourceR
Rscript -e "source('$<')"
endef
# DEPENDENCIES ##############################################################
###############################################################################
all: journal readme dot task
.PHONY: all
# make chart from .dot #########################################################
dot: $(FIG)/make.png
# make file .dot from the .makefile
$(FIG)/make.png: $(DT/P)/make.dot
@$(dot2png)
# make file .dot from the .makefile
$(DT/P)/make.dot: $(DIR)/Makefile
@$(make2dot)
# journals from Rmds ###########################################################
journal: $(JRN)/journal.pdf
# journal (with graph) render to pdf
$(JRN)/journal.pdf: $(JRN)/journal.Rmd $(FIG)/make.png
$(rmd2pdf)
# tast description from Rmds ###########################################################
task: $(JRN)/task.pdf
# task render to pdf
$(JRN)/task.pdf: $(JRN)/task.Rmd
$(rmd2pdf)
# README from Rmds #############################################################
readme: README.html
README.html: README.md
$(rmd2html)