-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
221 lines (162 loc) · 8.35 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# Standard Makefile boilerplate
SHELL = /bin/sh
.SUFFIXES:
RCMD = R --vanilla
# Sweave is always run in a subdir
Sweave = R_LIBS=../.libraries $(RCMD) CMD Sweave
TEX2PDF = latexmk -pdf
INSTALLLIB = $(RCMD) CMD INSTALL --no-multiarch --no-docs --library=.libraries
installpkg = mkdir -p .libraries ; R_LIBS=.libraries R --vanilla -e "install.packages('$(1)', repos = 'http://cran.rstudio.com/')" ; date > .libraries/$(1)/INSTALLED
LIBRARIES = .libraries/.d .libraries/RItools/INSTALLED .libraries/packages.txt
MAKEFIG = cd figures && $(Sweave)
HOST=$(shell hostname)
all: paper.pdf
### Paper Targets
# note: the figures only included at the latex step, so the individual
# sections do not need to be rebuilt when the figures change, but we notate
# the logical flow by tabbing in for the figures that used in each section
paper.pdf: figures/twoDplots.pdf \
BIB/big.bib \
styles/common.sty \
styles/notation.sty \
paper/paper.tex \
paper/introduction.tex \
paper/titlepage.tex \
coppock-replication/CoppockJEPS_figure2.pdf \
figures/ksvsssr-outcomes.pdf \
figures/ksvsssr-boxplots.pdf
cd paper && $(TEX2PDF) paper.tex
cp paper/paper.pdf .
## this next assumes that the authors names are on line 5.
paper-anon.pdf: paper.pdf
cd paper && cp paper.tex paper-anon.tex && sed -i.bak '5 s/^/%/' paper-anon.tex && $(TEX2PDF) paper-anon.tex
cp paper/paper-anon.pdf .
# a faster build than the paper, but less exact for figures
draft:
SEARCH_POINTS=10 REPETITIONS=100 make paper.pdf
# Libraries
.libraries/allpkgs.txt: .libraries/packages.txt .libraries/RItools/INSTALLED .libraries/Rmpi/INSTALLED
.libraries/.d:
mkdir -p .libraries
touch .libraries/.d
.libraries/packages.txt: .libraries/.d
R_LIBS=".libraries" $(RCMD) --file=pkgs/packages.R
echo "Packages last updated on" `date` > .libraries/packages.txt
R: $(LIBRARIES)
R_LIBS=".libraries" $(RCMD) --no-save --quiet
pkgs/RItools:
git submodule init && git submodule update
.libraries/RItools/INSTALLED: pkgs/RItools/R/* \
.libraries/SparseM/INSTALLED .libraries/xtable/INSTALLED .libraries/svd/INSTALLED .libraries/abind/INSTALLED .libraries/hexbin/INSTALLED .libraries/brew/INSTALLED
mkdir -p .libraries
cd pkgs/RItools && make package
$(INSTALLLIB) pkgs/RItools/$(shell cd pkgs/RItools && make current)
date > .libraries/RItools/INSTALLED
# the following are RItools dependencies: svd, abind, xtable, SparseM
.libraries/SparseM/INSTALLED:
$(call installpkg,SparseM)
.libraries/xtable/INSTALLED:
$(call installpkg,xtable)
.libraries/svd/INSTALLED:
$(call installpkg,svd)
.libraries/abind/INSTALLED:
$(call installpkg,abind)
.libraries/hexbin/INSTALLED:
$(call installpkg,hexbin)
.libraries/brew/INSTALLED:
$(call installpkg,brew)
.libraries/maptools/INSTALLED:
$(call installpkg,maptools)
.libraries/spdep/INSTALLED:
$(call installpkg,spdep)
.libraries/wnominate/INSTALLED:
$(call installpkg,wnominate)
### Paper components
.libraries/Rmpi/INSTALLED:
mkdir -p libraries
ifeq ($(findstring keeling,$(HOST)),keeling)
R_COMPILE_PKGS=1 R_LIBS=.libraries R --vanilla -e "install.packages('Rmpi', type='source', repos = 'http://cran.rstudio.com/',dependencies=TRUE,configure.args=c('--with-mpi=/sw/openmpi-1.6.4a-intel-14.0.3 --with-Rmpi-type=OPENMPI'))"
date > libraries/Rmpi/INSTALLED
else
R_COMPILE_PKGS=1 R_LIBS=.libraries R --vanilla -e "install.packages('Rmpi',type='source',repos = 'http://cran.rstudio.com/',dependencies=TRUE,configure.args=c('--with-Rmpi-include=/usr/local/include --with-Rmpi-libpath=/usr/local/lib --with-Rmpi-type=OPENMPI'))"
date > libraries/Rmpi/INSTALLED
endif
### Tables and Figures
figures/teststat2dfigs.txt: figures/teststat-parallel-summary.R \
simulation/teststat-parallel-results.rda \
code/plotting.R
R_LIBS=".libraries" $(RCMD) --file=figures/teststat-parallel-summary.R
figures/twoDplots.pdf: figures/teststat2dfigs.txt
figures/simulation-network-graph.tex: $(LIBRARIES) code/plotting.R simulation/setup.R figures/simulation-network-graph.Rnw
$(MAKEFIG) simulation-network-graph.Rnw
figures/ksvsssr-outcomes.pdf: figures/ksvsssr-outcomes.R simulation/simpledat.rda
R_LIBS=".libraries" $(RCMD) --file=figures/ksvsssr-outcomes.R
figures/ksvsssr-boxplots.pdf: figures/ksvsssr-boxplots.R simulation/ksvsssrpow-results.rda
R_LIBS=".libraries" $(RCMD) --file=figures/ksvsssr-boxplots.R
#### Simulations Galore ####
simulation/teststat-parallel.rda: $(LIBRARIES) simulation/setup.R simulation/teststat-parallel.R
R_LIBS=".libraries" $(RCMD) --file=simulation/teststat-parallel.R
simulation/teststat-parallel-results.rda: simulation/teststat-parallel.rda
R_LIBS=".libraries" $(RCMD) --file=simulation/teststat-parallel-results.R
simulation/ksvsssrpow.rda: $(LIBRARIES) simulation/ksvsssrpow.R simulation/ksvsssr-setup.txt \
code/setup-clusters.R \
simulation/setup.R \
code/teststatistics.R
ifeq ($(findstring keeling,$(HOST)),keeling)
sbatch ksvsssrpow.q
else
R_LIBS=".libraries" $(RCMD) --file=simulations/ksvsssrpow.R
endif
simulation/ksvsssr-setup.txt: $(LIBRARIES) simulation/ksvsssr-setup.R
R_LIBS=".libraries" $(RCMD) --file=simulation/ksvsssr-setup.R
simulation/simplealts.rda: simulation/ksvsssr-setup.txt
simulation/simpledat.rda: simulation/ksvsssr-setup.txt
simulation/simpletruth.rda: simulation/ksvsssr-setup.txt
simulation/ksvsssrpow-results.rda: simulation/ksvsssrpow-results.R simulation/ksvsssrpow.rda
R_LIBS=".libraries" $(RCMD) --file=simulation/ksvsssrpow-results.R
### Two cleaning tasks. The default clean does not remove *.rda files, deepclean does
clean:
git ls-files --others --exclude="*rda*" --exclude=".libraries" | xargs rm -rf
deepclean:
git clean -xdf
## Right now my idea is to run git ls-files --others > filestodelete.txt and then add that list to the archive and feel it to rm
## below.
filestodelete.txt:
git ls-files --others > filestodelete.txt
echo ".libraries" >> filetodelete.txt
deepclean-repo: filestodelete.txt
cat filestodelete.txt | xargs rm -rf
### Export Tasks
# the archive export includes the .Rnw files so the people can tweak the code if they wish
ARCHIVENAME=teststatistics-randomization-inference-interference
$(ARCHIVENAME).tar.gz: Makefile README.md filestodelete.txt paper/* simulation/* code/* BIB/* figures/* styles/*
rm -rf $(ARCHIVENAME)
mkdir $(ARCHIVENAME)
rsync -a --exclude-from=.gitignore --exclude=.git* \
. $(ARCHIVENAME)
tar -cz $(ARCHIVENAME) > $(ARCHIVENAME).tar.gz
archive: $(ARCHIVENAME).tar.gz
# the static export dumps all the .tex, .pdf, etc files needed for paper.pdf
$(ARCHIVENAME)-static.tar.gz: paper.pdf
rm -rf $(ARCHIVENAME)-static
mkdir $(ARCHIVENAME)-static
grep INPUT paper/paper.fls | grep -v texlive | sed "s/^INPUT /paper\//" > $(ARCHIVENAME)-static/MANIFEST
rsync --files-from=$(ARCHIVENAME)-static/MANIFEST . $(ARCHIVENAME)-static
sed "s/\\\\bibliographystyle.*//" $(ARCHIVENAME)-static/paper/paper.tex | sed "s/\\\\bibliography.*/\\\\input{paper.bbl}/" > paper.tmp
mv paper.tmp $(ARCHIVENAME)-static/paper/paper.tex
echo "#!/bin/sh\ncd paper\nlatexmk -pdf -bibtex- paper.tex\ncp paper.pdf ..\n" > $(ARCHIVENAME)-static/build.sh
chmod +x $(ARCHIVENAME)-static/build.sh
tar -cz $(ARCHIVENAME)-static > $(ARCHIVENAME)-static.tar.gz
static: $(ARCHIVENAME)-static.tar.gz
#### Replication of Coppock (2014)
coppock-replication/CoppockJEPS_10000Randomizations.rdata: coppock-replication/CoppockJEPS_10000Randomizations.R coppock-replication/nm.replication.tab \
.libraries/spdep/INSTALLED .libraries/maptools/INSTALLED .libraries/wnominate/INSTALLED
cd coppock-replication && R_LIBS=../.libraries $(RCMD) -f CoppockJEPS_10000Randomizations.R
coppock-replication/CoppockJEPS.rdata: coppock-replication/CoppockJEPS_10000Randomizations.rdata coppock-replication/CoppockJEPS_datapreparation.R
cd coppock-replication && R_LIBS=../.libraries $(RCMD) -f CoppockJEPS_datapreparation.R
coppock-replication/fig2.rdata: code/teststatistics.R coppock-replication/CoppockJEPS_figure2code.R coppock-replication/CoppockJEPS.rdata
cd coppock-replication && R_LIBS=../.libraries $(RCMD) -f CoppockJEPS_figure2code.R
coppock-replication/CoppockJEPS_figure2.pdf: coppock-replication/fig2.rdata coppock-replication/CoppockJEPS_figure2graphic.R
cd coppock-replication && R_LIBS=../.libraries $(RCMD) -f CoppockJEPS_figure2graphic.R
coppock-replication/CoppockJEPS_figure3a.pdf: coppock-replication/CoppockJEPS.rdata coppock-replication/CoppockJEPS_figure3code.R
cd coppock-replication && R_LIBS=../.libraries $(RCMD) -f CoppockJEPS_figure3code.R