11library(" revdepcheck" )
22options(warn = 1L )
33
4- availableCores <- function () {
5- getenv <- function (name ) as.integer(Sys.getenv(name , NA_character_ ))
6- getopt <- function (name ) as.integer(getOption(name , NA_integer_ ))
4+ available_cores <- function () {
5+ getenv <- function (name ) {
6+ as.integer(Sys.getenv(name , NA_character_ ))
7+ }
8+ getopt <- function (name ) {
9+ as.integer(getOption(name , NA_integer_ ))
10+ }
711 if (is.finite(n <- getopt(" mc.cores" ) + 1L )) return (n )
812 if (is.finite(n <- getopt(" Ncpus" ) + 1L )) return (n )
913 if (is.finite(n <- getenv(" PBS_NUM_PPN" ))) return (n )
@@ -12,16 +16,109 @@ availableCores <- function() {
1216 1L
1317}
1418
15- if (file_test(" -f" , p <- Sys.getenv(" R_CHECK_ENVIRON" , " ~/.R/check.Renviron" ))) {
16- cat(sprintf(" R CMD check will use env vars from %s\n " , sQuote(p )))
17- cat(sprintf(" To disable, set 'R_CHECK_ENVIRON=false' (a fake pathname)\n " ))
19+ precheck <- function () {
20+ # # WORKAROUND: Remove checked pkgs that use file links, which otherwise
21+ # # produce warnings which are promoted to errors by revdepcheck.
22+ unlink(" revdep/checks/aroma.affymetrix" , recursive = TRUE )
1823}
1924
20- envs <- grep(" ^_R_CHECK_" , names(Sys.getenv()), value = TRUE )
21- if (length(envs ) > 0L ) {
22- cat(sprintf(" Detected _R_CHECK_* env vars that will affect R CMD check: %s\n " ,
23- paste(sQuote(envs ), collapse = " , " )))
25+ check <- function () {
26+ if (file_test(" -f" , p <- Sys.getenv(" R_CHECK_ENVIRON" , " ~/.R/check.Renviron" ))) {
27+ cat(sprintf(" R CMD check will use env vars from %s\n " , sQuote(p )))
28+ cat(sprintf(" To disable, set 'R_CHECK_ENVIRON=false' (a fake pathname)\n " ))
29+ }
30+
31+ envs <- grep(" ^_R_CHECK_" , names(Sys.getenv()), value = TRUE )
32+ if (length(envs ) > 0L ) {
33+ cat(sprintf(" Detected _R_CHECK_* env vars that will affect R CMD check: %s\n " ,
34+ paste(sQuote(envs ), collapse = " , " )))
35+ }
36+
37+ precheck()
38+ revdep_check(bioc = TRUE , num_workers = available_cores(),
39+ timeout = as.difftime(20 , units = " mins" ), quiet = FALSE )
40+ }
41+
42+ todo <- function () {
43+ pkgs <- tryCatch(revdep_todo(), error = function (ex ) NA )
44+ if (identical(pkgs , NA )) {
45+ cat(" Revdepcheck has not been initiated\n " )
46+ } else if (length(pkgs ) == 0 ) {
47+ cat(" There are no packages on the revdepcheck todo list\n " )
48+ } else {
49+ cat(sprintf(" %d. %s\n " , seq_along(pkgs ), pkgs ))
50+ }
2451}
2552
26- revdep_check(bioc = TRUE , num_workers = availableCores(),
27- timeout = as.difftime(20 , units = " mins" ), quiet = FALSE )
53+ parse_pkgs <- function (pkgs ) {
54+ pkgs <- unlist(strsplit(pkgs , split = " ," , fixed = TRUE ))
55+ pkgs <- gsub(" [ \t '\" ‘’]" , " " , pkgs )
56+ sort(unique(pkgs ))
57+ }
58+
59+ revdep_init <- function () {
60+ if (! revdepcheck ::: db_exists(" ." )) revdepcheck ::: db_setup(" ." )
61+ }
62+
63+ revdep_todo_reset <- function () {
64+ revdep_init()
65+ db <- revdepcheck ::: db(" ." )
66+ df <- data.frame (package = character (0L ), stringsAsFactors = FALSE )
67+ DBI :: dbWriteTable(db , " todo" , df , overwrite = TRUE , append = FALSE )
68+ }
69+
70+ revdep_children <- local({
71+ cache <- list ()
72+ function (pkg = NULL ) {
73+ if (is.null(pkg )) pkg <- desc :: desc(file = " DESCRIPTION" )$ get(" Package" )
74+ pkgs <- cache [[pkg ]]
75+ if (is.null(pkgs )) {
76+ pkgs <- revdepcheck ::: cran_revdeps(pkg )
77+ pkgs <- setdiff(pkgs , pkg ) # # WORKAROUND
78+ cache [[pkg ]] <- pkgs
79+ }
80+ pkgs
81+ }
82+ })
83+
84+ args <- base :: commandArgs()
85+ if (" --reset" %in% args ) {
86+ revdep_reset()
87+ } else if (" --todo-reset" %in% args ) {
88+ revdep_todo_reset()
89+ todo()
90+ } else if (" --todo" %in% args ) {
91+ todo()
92+ } else if (" --add" %in% args ) {
93+ pos <- which(" --add" == args )
94+ pkgs <- parse_pkgs(args [seq(from = pos + 1L , to = length(args ))])
95+ revdep_add(packages = pkgs )
96+ todo()
97+ } else if (" --add-broken" %in% args ) {
98+ revdep_add_broken()
99+ todo()
100+ } else if (" --add-all" %in% args ) {
101+ revdep_init()
102+ pkgs <- revdep_children()
103+ for (pkg in pkgs ) {
104+ pkgs <- c(pkgs , revdepcheck ::: cran_revdeps(pkg ))
105+ }
106+ pkgs <- unique(pkgs )
107+ revdep_add(packages = pkgs )
108+ todo()
109+ } else if (" --add-grandchildren" %in% args ) {
110+ revdep_init()
111+ pkgs <- NULL
112+ for (pkg in revdep_children()) {
113+ pkgs <- c(pkgs , revdepcheck ::: cran_revdeps(pkg ))
114+ }
115+ pkgs <- unique(pkgs )
116+ revdep_add(packages = pkgs )
117+ todo()
118+ } else if (" --install" %in% args ) {
119+ pos <- which(" --install" == args )
120+ pkgs <- parse_pkgs(args [seq(from = pos + 1L , to = length(args ))])
121+ crancache :: install_packages(pkgs )
122+ } else {
123+ check()
124+ }
0 commit comments