-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathrcc.r
executable file
·92 lines (78 loc) · 3.33 KB
/
rcc.r
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
#!/usr/bin/env -S r -t
##
## Call 'rcmdcheck' on a package
##
## Copyright (C) 2016 - 2024 Dirk Eddelbuettel
##
## Released under GPL (>= 2)
## load docopt package from CRAN
library(docopt)
## configuration for docopt
doc <- "Usage: rcc.r [-h] [-x] [-c] [-f] [-q] [-v] [--args ARGS] [--libpath LIBP] [--repos REPO] [--erroron ERRON] [PATH...]
-c --as-cran should '--as-cran' be added to ARGS [default: FALSE]
-a --args ARGS additional arguments to be passed to 'R CMD CHECK' [default: ]
-l --libpath LIBP additional library path to be used by 'R CMD CHECK' [default: ]
-r --repos REPO additional repositories to be used by 'R CMD CHECK' [default: ]
-f --fast should vignettes and manuals be skipped [default: FALSE]
-v --valgrind should tests run with 'valgrind' debug tool [default: FALSE]
-e --erroron ERRON whether to throw an error on failure [default: never]
-q --quiet should 'rcmdcheck' be called quietly [default: FALSE]
-h --help show this help text
-x --usage show help and short example usage"
opt <- docopt(doc) # docopt parsing
if (opt$usage) {
cat(doc, "\n\n")
cat("Examples:
rcc.r # check repo in current (working) director
rcc.r -c # run as R CMD check --as-crn
rcc.r is part of littler which brings 'r' to the command-line.
See http://dirk.eddelbuettel.com/code/littler.html for more information.\n")
q("no")
}
erroron <- switch(opt$erroron,
never = "never",
error = "error",
warning = "warning",
note = "note",
"badarg")
if (erroron=="badarg")
stop("Inadmissable argument for '--erroron' option.", call.=FALSE)
if (is.null(opt$args)) { # special treatment for --args and -c
if (opt$as_cran) {
opt$args <- "--as-cran"
} else {
opt$args <- character()
}
} else {
if (opt$as_cran) {
opt$args <- c(opt$args, "--as-cran")
}
}
if (opt$fast) {
opt$args <- c(opt$args, "--ignore-vignettes", "--no-manual")
}
if (opt$valgrind) {
opt$args <- c(opt$args, "--use-valgrind")
}
if (length(opt$PATH) == 0) opt$PATH <- "." # default argument current directory
if (is.null(opt$libpath)) opt$libpath <- .libPaths() # default library pathr
if (is.null(opt$repos)) opt$repos <- getOption("repos") # default repos
if (requireNamespace("rcmdcheck", quietly=TRUE) == FALSE)
stop("This command requires the 'rcmdcheck' package.", call. = FALSE)
suppressMessages(library(rcmdcheck))
Sys.setenv("_R_CHECK_TESTS_NLINES_"="0") # ensure all errors shown
rccwrapper <- function(pa, qu, ar, li, re, eo) {
res <- rcmdcheck(path=pa, quiet=qu, args=ar, libpath=li, repos=re, error_on=eo)
print(res)
res
}
rc <- sapply(opt$PATH, # iterate over arguments
rccwrapper, # calling 'rcmdcheck()' with arguments
opt$quiet, # quiet argument, default false
opt$args, # args arguments, possibly with --as-cran
opt$libpath, # libpath argument
opt$repos, # repos argument
erroron, # error_on argument
simplify=FALSE)
status <- max(sapply(rc, "[[", "status"))
q(status=status)