-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
169 lines (136 loc) · 5.88 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
## Makefile for generating R packages.
## original by 2011 Andrew Redd
## https://gist.github.com/halpo/1374344
## Modified by kaz-yos for a different directory structure.
## To be put in the package directory.
## The build and check output files are put in the package directory.
## These files as well as Makefile have to be .Rbuildignore.
## writing rules
## https://www.gnu.org/software/make/manual/html_node/Rules.html#Rules
## Extract the package name and version from the DESCRIPTION file.
PKG_NAME=$(shell grep -i ^package: DESCRIPTION | cut -d : -d \ -f 2)
PKG_VERSION=$(shell grep -i ^version: DESCRIPTION | cut -d : -d \ -f 2)
## Define files to check for updates
R_FILES := $(wildcard R/*.R)
TEST_FILES := $(wildcard tests/testthat/*.R)
SAS_FILES := $(wildcard tests/reference_results/sas-*.sas)
SRC_FILES := $(wildcard src/*) $(addprefix src/, $(COPY_SRC))
VIG_FILES := $(wildcard vignettes/*)
DATA_RAW_FILES := $(wildcard data-raw/*)
DATA_FILES := $(wildcard data/*)
PKG_FILES := DESCRIPTION NAMESPACE NEWS.md $(R_FILES) $(TEST_FILES) $(SRC_FILES) $(VIG_FILES) $(DATA_RAW_FILES) $(DATA_FILES)
## .PHONY to allow non-file targets (file targets should not be here)
## https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
.PHONY: test lint winbuild vignettes readme pkgdown build check check_devtools revdep install sas clean data
### Define targets
## Data generation when raw files are updated.
## This may not work when adding new datasets.
data: $(DATA_FILES)
$(DATA_FILES): $(DATA_RAW_FILES)
cd ./data-raw; Rscript vv2015.R
## test just runs testthat scripts. No dependencies.
test: NAMESPACE
Rscript -e 'options(width = 120); options("testthat.progress.max_fails" = Inf); devtools::test()' | tee test-all.txt
## lintr
# https://github.com/jimhester/lintr#continuous
lint: NAMESPACE
Rscript -e 'options(width = 120); lintr::lint_package()' | tee lint_package.txt
## winbuild always build regardless of file update status
## Links to results e-mailed (no useful output locally)
winbuild:
Rscript -e "devtools::check_win_devel()"
Rscript -e "devtools::check_win_release()"
## Build vignettes in inst/doc
vignettes: ${VIG_FILES}
Rscript -e "devtools::build_vignettes()"
## Build README.md
readme: README.Rmd
Rscript -e "rmarkdown::render('README.Rmd', output_format = 'md_document', output_file = 'README.md')"
## Build website
## https://pkgdown.r-lib.org
pkgdown: vignettes readme NAMESPACE
Rscript -e "pkgdown::build_site()"
## build depends on the *.tar.gz file, i.e., its own product.
## *.tar.gz file is defined seprately to prevent build execution on every invocation.
build: $(PKG_NAME)_$(PKG_VERSION).tar.gz
## (file target) The *.tar.gz file depends on package files including NAMESPACE,
## and build *.tar.gz file from these.
$(PKG_NAME)_$(PKG_VERSION).tar.gz: $(PKG_FILES)
Rscript -e "devtools::build(pkg = '.', path = '.', manual = TRUE)"
## (file target) NAMESPACE depends on *.R files, and excecute roxygen2 on these.
## methods::is() is not automatically loaded by roxygen2 version 4
NAMESPACE: $(R_FILES)
Rscript -e "devtools::document('.')"
## check requires the *.tar.gz file, and execute strict tests on it.
check: $(PKG_NAME)_$(PKG_VERSION).tar.gz
R CMD check --as-cran ./$(PKG_NAME)_$(PKG_VERSION).tar.gz | tee cran-check.txt
check_devtools: $(PKG_NAME)_$(PKG_VERSION).tar.gz
Rscript -e "options(width = 120); devtools::check(pkg = '.', check_dir = '.', manual = TRUE)" | tee cran-check.txt
## revdep requires the *.tar.gz file, and execute strict tests on it.
## https://github.com/r-lib/revdepcheck
revdep: $(PKG_NAME)_$(PKG_VERSION).tar.gz
Rscript -e "devtools::revdep()"
Rscript -e "options(width = 120); revdepcheck::revdep_check(num_workers = 6); revdepcheck::revdep_summary()" | tee revdep_check.txt
revdep_clean:
Rscript -e "revdepcheck::revdep_reset()"
## install requires the *.tar.gz file, and execute installation using it.
install: $(PKG_NAME)_$(PKG_VERSION).tar.gz
Rscript -e "devtools::install('.')"
## run sas analyses
# https://stackoverflow.com/questions/1789594/how-do-i-write-the-cd-command-in-a-makefile
# It should only run when 01_generate_sas_data.R is updated.
sas_data: tests/reference_results/01_generate_sas_data.R
cd tests/reference_results/ ; \
Rscript 01_generate_sas_data.R 2>&1 | tee 01_generate_sas_data.R.txt
# It should only run when either one of these are updated.
sas_scripts: tests/reference_results/02_generate_sas_macro_calls.R tests/reference_results/02_generate_sas_macro_calls_helpers.R
cd tests/reference_results/ ; \
Rscript 02_generate_sas_macro_calls.R 2>&1 | tee 02_generate_sas_macro_calls.R.txt
sas_scripts_clean:
-for f in $(SAS_FILES); do \
rm $$f ; \
done;
# This one can only run on a linux server with sas.
# This depends on up-to-date sas_data and sas_scripts.
# These two must depend on files so that they do not run every time.
# This fails without harm on a system without the sas command.
sas: sas_data sas_scripts
-cd tests/reference_results/ ; \
for f in $(subst tests/reference_results/,,$(SAS_FILES)) ; do \
sas $$f ; \
done;
# It depends on sas which should be ok on an environment without sas.
sas_extract: sas
for f in $(subst .sas,.lst,$(SAS_FILES)); do \
cat $${f} | grep " cde \| nde \| cde=nde \| [pt]nde \| nie \| [pt]nie \| total effect " > $${f%lst}txt ; \
done;
sas_clean:
-for f in $(subst .sas,.log,$(SAS_FILES)); do \
rm $$f ; \
done;
-for f in $(subst .sas,.lst,$(SAS_FILES)); do \
rm $$f ; \
done;
## clean has no dependency, and execute removal of make output files.
clean: revdep_clean
-rm -f $(PKG_NAME)_$(PKG_VERSION).tar.gz
-rm -r -f $(PKG_NAME).Rcheck
-rm -r -f man/*.Rd
-rm -r -f NAMESPACE
## Define a target "list" that just prints the names of files.
.PHONY: list
list:
@echo "R files:"
@echo $(R_FILES)
@echo
@echo "SAS files:"
@echo $(SAS_FILES)
@echo
@echo "Test files:"
@echo $(TEST_FILES)
@echo
@echo "Source files:"
@echo $(SRC_FILES)
@echo
@echo "Vignettes:"
@echo $(VIG_FILES)