This repository has been archived by the owner on May 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdt
executable file
·158 lines (145 loc) · 4.58 KB
/
dt
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
#!/usr/bin/env Rscript
exit = function(status, msg, ..., help=FALSE) {
if (!missing(msg))
cat("Error: ", sprintf(msg, ...), "\n", sep="")
if (help) {
cat("\n")
print_help(parser)
}
quit(save="no", status=status)
}
try_install = function(pkgs) {
silent_require = function(x)
suppressPackageStartupMessages(require(x, character.only=TRUE))
lapply(pkgs, function(pkg) {
if (!silent_require(pkg)) {
ok = try(install.packages(pkg))
if (inherits(ok, "try-error") || !silent_require(pkg))
exit(1L, "Unable to install package '%s'", pkg)
}
})
invisible(TRUE)
}
get_package = function(dir) {
if (is.na(dir)) {
fn = file.path(getwd(), c(".", "..", file.path("..", "..")), "DESCRIPTION")
} else {
fn = file.path(dir, "DESCRIPTION")
}
fn = head(Filter(file.exists, fn), 1L)
if (!length(fn))
exit(1L, "DESCRIPTION file not found", help=FALSE)
dir = dirname(normalizePath(fn))
as.package(dir)
}
try_install(c("methods", "optparse", "devtools", "roxygen2", "testthat", "covr"))
description = "
Available commands:
build: Build R source package
clean: Remove compiled dlls from src/
check: Checks package and variable usage
cov: Outputs code coverage statistics using covr
deps: Install required dependencies, including suggests
document: Build documentation using roxygen2
install: Install R package and required dependencies
make: Build documentation, vignettes and install package
revdep: Check reverse dependencies
test: Run unit tests
usage: Check variable usage using codetools
winbuild: Upload package to win-builder
Argument DIR must point to directory containing the DESCRIPTION file.
If not provided, DESCRIPTION file is searched in current directory and
up to two parents."
opts = list(
make_option("--devel", action="store_true",
default=FALSE, dest="devel",
help="Test against devel instead of release for winbuild."),
make_option("--quick", action="store_true",
default=FALSE, dest="quick",
help="Set 'quick' in devtools::install."),
make_option("--filter", action="store", type="character",
default=NULL, dest="filter",
help="Filter passed to devtools::test()."),
make_option("--expensive", action="store_true", type="character",
default=FALSE, dest="expensive",
help="Set the environment variable for BBmisc::isExpensiveExampleOk()"),
make_option("--threads", action="store",
default=0L, dest="threads", type="integer",
help="Define how many threads to use. Defaults to 0 (autodetect).")
)
parser = OptionParser(usage="%prog [options] command [DIR]",
option_list=opts,
description=description,
)
args = parse_args(parser, positional_arguments=TRUE)
if (length(args$args) == 0L || length(args$args) > 2L)
exit(1L, "Incorrect number of arguments", help=TRUE)
pkg = get_package(args$args[2L])
if (args$options$threads > 0L) {
options(Ncpus=args$options$threads)
} else {
options(Ncpus=parallel::detectCores())
}
if (args$options$expensive) {
Sys.setenv(R_EXPENSIVE_EXAMPLE_OK = "TRUE")
}
switch(args$args[1L],
make = {
document(pkg)
install(pkg, quick=args$options$quick,
dependencies=c("Depends", "Imports", "LinkingTo"),
build_vignettes = TRUE)
},
cov = {
package_coverage(args$args[2L])
},
check = {
install_deps(pkg, dependencies=TRUE)
check(pkg, check_dir = ".")
},
usage = {
try_install("codetools")
load_all(pkg, export_all=FALSE)
checkUsagePackage(pkg$package)
},
install = {
install(pkg, quick=args$options$quick,
dependencies=c("Depends", "Imports", "LinkingTo"))
},
test = {
test(pkg, filter=args$options$filter)
},
build = {
build(pkg)
},
deps = {
install_deps(pkg, dependencies=TRUE)
},
document = {
document(pkg)
},
clean = {
clean_dll(pkg)
},
winbuild = {
document(pkg)
build_win(pkg,
version=ifelse(args$options$devel, "R-devel", "R-release"))
},
revdep = {
# libpath: check devtools options, otherwise take home dir path.
# if that path does not exist, create it
lib = file.path(path.expand("~"), ".dt", "rlib")
lib = getOption("devtool.revdep.libpath", lib)
if (!file.exists(lib))
dir.create(lib, recursive = TRUE)
# the check dir must be accessible after we leave the script, so we can look at it
check.dir = file.path(".", "rev-dep-check")
res = revdep_check(pkg, libpath = lib, check_dir = check.dir)
# we probably want to have an exit code on error here
cat(revdep_check_summary(res))
},
exit(1L, "Unknown command '%s'", args$args[1L], help=TRUE)
)
exit(0L)
# vim: ft=r