-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
59 lines (45 loc) · 1.56 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
.PHONY: clean docs start setwd check install load render
.DEFAULT_GOAL := help
define BROWSER_PYSCRIPT
import os, webbrowser, sys
from urllib.request import pathname2url
# The input is expected to be the full HTML filename
filename = sys.argv[1]
filepath = os.path.abspath(os.path.join("./vignettes/", filename))
webbrowser.open("file://" + pathname2url(filepath))
endef
export BROWSER_PYSCRIPT
define PRINT_HELP_PYSCRIPT
import re, sys
for line in sys.stdin:
match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line)
if match:
target, help = match.groups()
print("%-20s %s" % (target, help))
endef
export PRINT_HELP_PYSCRIPT
BROWSER := python3 -c "$$BROWSER_PYSCRIPT"
help:
@python3 -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)
clean: ## remove all build, test, coverage and Python artifacts
rm -f .Rbuildignore
rm -f .Rhistory
rm -f *.RData
rm -f *.Rproj
rm -rf .Rproj.user
start: ## start or restart R session
Rscript -e "system('R')"
setwd: ## set working directory
Rscript -e "setwd(getwd())"
docs: clean setwd ## generate docs
Rscript -e "devtools::document('.')"
check: clean setwd ## check package
Rscript -e "devtools::check('.')"
install: clean setwd ## install package
Rscript -e "devtools::install('.')"
load: clean setwd ## load all (when developing the package)
Rscript -e "devtools::load_all('.')"
render: ## run markdown file in /vignettes
@read -p "Enter the name of the Rmd file (without extension): " filename; \
Rscript -e "rmarkdown::render(paste0('./vignettes/', '$$filename', '.Rmd'))"; \
python3 -c "$$BROWSER_PYSCRIPT" "$$filename.html"