Skip to content

Commit fe68a37

Browse files
committed
Add options support
1 parent d2af9ad commit fe68a37

27 files changed

+356
-112
lines changed

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: checked
22
Title: Systematically Run R CMD Checks
3-
Version: 0.2.3.9004
3+
Version: 0.2.3.9005
44
Authors@R:
55
c(
66
person(
@@ -36,6 +36,7 @@ Imports:
3636
cli,
3737
igraph,
3838
jsonlite,
39+
options,
3940
R6,
4041
rcmdcheck,
4142
utils (>= 3.6.2),

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export(run)
7575
export(source_check_tasks_df)
7676
export(task_spec)
7777
import(cli)
78+
import(options)
7879
importFrom(R6,R6Class)
7980
importFrom(callr,r_process)
8081
importFrom(cli,make_spinner)

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121

2222
* Prettify output by stripping excessive new lines.
2323

24+
* `checked` now depends on `options`
25+
26+
* Expose `...` allowing customization of check subprocesses when creating checks df.
27+
2428
# checked 0.2.3
2529

2630
* Use custom `checked` `finisher`'s instead of the `processx` `finalizer`'s

R/check.R

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@
1919
#' to pull sources for reverse dependencies. In some cases, for instance using
2020
#' binaries on Linux, we want to use different repositories when pulling
2121
#' sources to check and different when installing dependencies.
22-
#' @param restore `logical` indicating whether output directory should be
23-
#' unlinked before running checks. If `FALSE`, an attempt will me made to
24-
#' restore previous progress from the same `output`
25-
#' @param ... Additional arguments passed to [`run()`]
22+
#' @param ... Additional arguments passed to [`checked-task-df`] and [`run()`]
2623
#'
2724
#' @return
2825
#' [`check_design()`] R6 class storing all the details
@@ -48,6 +45,7 @@ NULL
4845
#' identify changes in reverse dependency behaviors.
4946
#'
5047
#' @inheritParams check_functions
48+
#' @inheritParams options_params
5149
#' @inheritParams run
5250
#'
5351
#' @inherit check_functions return
@@ -61,10 +59,15 @@ check_rev_deps <- function(
6159
lib.loc = .libPaths(), # nolint object_name_linter
6260
repos = getOption("repos"),
6361
reverse_repos = repos,
64-
restore = TRUE,
62+
restore = options::opt("restore"),
6563
reporter = reporter_default(),
6664
...) {
67-
checks <- rev_dep_check_tasks_df(path = path, repos = reverse_repos)
65+
66+
checks <- rev_dep_check_tasks_df(
67+
path = path,
68+
repos = reverse_repos,
69+
...
70+
)
6871

6972
plan <- check_design$new(
7073
checks,
@@ -87,6 +90,7 @@ check_rev_deps <- function(
8790
#' as a `Suggests` dependency.
8891
#'
8992
#' @inheritParams check_functions
93+
#' @inheritParams options_params
9094
#' @inheritParams run
9195
#'
9296
#' @inherit check_functions return
@@ -99,9 +103,15 @@ check_dev_rev_deps <- function(
99103
output = tempfile(paste(utils::packageName(), Sys.Date(), sep = "-")),
100104
lib.loc = .libPaths(), # nolint object_name_linter
101105
repos = getOption("repos"),
102-
restore = TRUE,
106+
restore = options::opt("restore"),
103107
...) {
104-
checks <- rev_dep_check_tasks_df(path = path, repos = repos, versions = "dev")
108+
109+
checks <- rev_dep_check_tasks_df(
110+
path = path,
111+
repos = repos,
112+
versions = "dev",
113+
...
114+
)
105115

106116
plan <- check_design$new(
107117
checks,
@@ -123,6 +133,7 @@ check_dev_rev_deps <- function(
123133
#' `path` directory
124134
#'
125135
#' @inheritParams check_functions
136+
#' @inheritParams options_params
126137
#' @inheritParams run
127138
#'
128139
#' @inherit check_functions return
@@ -135,9 +146,10 @@ check_pkgs <- function(
135146
output = tempfile(paste(utils::packageName(), Sys.Date(), sep = "-")),
136147
lib.loc = .libPaths(), # nolint object_name_linter
137148
repos = getOption("repos"),
138-
restore = TRUE,
149+
restore = options::opt("restore"),
139150
...) {
140-
checks <- source_check_tasks_df(path)
151+
152+
checks <- source_check_tasks_df(path, ...)
141153

142154
plan <- check_design$new(
143155
checks,
@@ -158,6 +170,7 @@ check_pkgs <- function(
158170
#' (non-recursively) and passes them to the [`check_pkgs()`]
159171
#'
160172
#' @inheritParams check_functions
173+
#' @inheritParams options_params
161174
#' @inheritParams run
162175
#'
163176
#' @inherit check_functions return
@@ -170,7 +183,7 @@ check_dir <- function(
170183
output = tempfile(paste(utils::packageName(), Sys.Date(), sep = "-")),
171184
lib.loc = .libPaths(), # nolint object_name_linter
172185
repos = getOption("repos"),
173-
restore = TRUE,
186+
restore = options::opt("restore"),
174187
...) {
175188
dirs <- list.dirs(path, full.names = TRUE, recursive = FALSE)
176189
r_packages <- dirs[vlapply(dirs, path_is_pkg)]

R/check_design.R

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ check_design <- R6::R6Class( # nolint cyclocomp_linter
8686
output = tempfile(paste(packageName(), Sys.Date(), sep = "-")),
8787
lib.loc = .libPaths(), # nolint object_name_linter
8888
repos = getOption("repos"),
89-
restore = TRUE,
89+
restore = options::opt("restore"),
9090
...
9191
) {
9292
# Make sure all aliases are unique
@@ -98,10 +98,25 @@ check_design <- R6::R6Class( # nolint cyclocomp_linter
9898
"Custom package aliases cannot be duplicates of check aliases" =
9999
!any(uulist(drlapply(df$custom, `[[`, "alias")) %in% df$alias)
100100
)
101-
102-
if (!restore) unlink(output, recursive = TRUE, force = TRUE)
101+
102+
if (dir.exists(output)) {
103+
if (is.na(restore))
104+
restore <- switch(
105+
menu(
106+
c("Yes", "No"),
107+
title = "Do you want to restore previous results?"
108+
),
109+
"1" = TRUE,
110+
"2" = FALSE
111+
)
112+
113+
if (!restore) {
114+
unlink(output, recursive = TRUE, force = TRUE)
115+
}
116+
}
117+
103118
dir_create(output)
104-
119+
105120
self$input <- df
106121
self$output <- output
107122
private$n <- n

R/checks_df.R

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ empty_checks_df <- data.frame(
2121
#' @param path path to the package source. Can be either a single source
2222
#' code directory or a directory containing multiple package source code
2323
#' directories.
24+
#' @param ... parameters passed to the task specs allowing to customize
25+
#' subprocesses.
2426
#'
2527
#' @return The check schedule `data.frame` with the following columns:
2628
#'
@@ -61,7 +63,8 @@ NULL
6163
rev_dep_check_tasks_df <- function(
6264
path,
6365
repos = getOption("repos"),
64-
versions = c("dev", "release")
66+
versions = c("dev", "release"),
67+
...
6568
) {
6669
stopifnot(
6770
"rev_dep_check_tasks_df requires path argument of length 1" =
@@ -113,7 +116,7 @@ rev_dep_check_tasks_df <- function(
113116

114117
if ("dev" %in% versions) {
115118
df_dev$alias <- paste0(df_dev$alias, " (dev)")
116-
df_dev$package <- task_specs_function(revdeps, repos, df_dev$alias, "new")
119+
df_dev$package <- task_specs_function(revdeps, repos, df_dev$alias, "new", ...)
117120
df_dev$custom <- rep(list(custom_install_task_spec(
118121
alias = paste0(package, " (dev)"),
119122
package_spec = package_spec_source(name = package, path = path),
@@ -124,7 +127,7 @@ rev_dep_check_tasks_df <- function(
124127
if ("release" %in% versions) {
125128
package_v <- ap[package, "Version"]
126129
df_rel$alias <- paste0(df_rel$alias, " (v", package_v, ")")
127-
df_rel$package <- task_specs_function(revdeps, repos, df_rel$alias, "old")
130+
df_rel$package <- task_specs_function(revdeps, repos, df_rel$alias, "old", ...)
128131
df_rel$custom <- rep(list(custom_install_task_spec(
129132
alias = paste0(package, " (release)"),
130133
package_spec = package_spec(name = package, repos = repos),
@@ -147,45 +150,60 @@ rev_dep_check_tasks_df <- function(
147150
df
148151
}
149152

150-
rev_dep_check_tasks_specs <- function(packages, repos, aliases, revdep) {
153+
rev_dep_check_tasks_specs <- function(packages, repos, aliases, revdep, ...) {
151154
list_of_task_spec(mapply(
152-
function(p, a) {
155+
function(
156+
p,
157+
a,
158+
env = NULL,
159+
args = NULL,
160+
build_args = NULL
161+
) {
153162
revdep_check_task_spec(
154163
alias = a,
155164
package_spec = package_spec(name = p, repos = repos),
156-
env = DEFAULT_R_CMD_CHECK_VARIABLES,
157-
args = DEFAULT_CHECK_ARGS,
158-
build_args = DEFAULT_BUILD_ARGS,
165+
env = env,
166+
args = args,
167+
build_args = build_args,
159168
revdep = revdep
160169
)
161170
},
162171
packages,
163172
aliases,
164173
SIMPLIFY = FALSE,
165-
USE.NAMES = FALSE
174+
USE.NAMES = FALSE,
175+
MoreArgs = list(...)
166176
))
167177
}
168178

169179
rev_dep_check_tasks_specs_development <- function(
170180
packages,
171181
repos,
172182
aliases,
183+
revdep,
173184
...
174185
) {
175186
list_of_task_spec(mapply(
176-
function(p, a) {
187+
function(
188+
p,
189+
a,
190+
env = NULL,
191+
args = NULL,
192+
build_args = NULL
193+
) {
177194
check_task_spec(
178195
alias = a,
179196
package_spec = package_spec(name = p, repos = repos),
180-
env = DEFAULT_R_CMD_CHECK_VARIABLES,
181-
args = DEFAULT_CHECK_ARGS,
182-
build_args = DEFAULT_BUILD_ARGS
197+
env = env,
198+
args = args,
199+
build_args = build_args
183200
)
184201
},
185202
packages,
186203
aliases,
187204
SIMPLIFY = FALSE,
188-
USE.NAMES = FALSE
205+
USE.NAMES = FALSE,
206+
MoreArgs = list(...)
189207
))
190208
}
191209

@@ -196,7 +214,7 @@ rev_dep_check_tasks_specs_development <- function(
196214
#'
197215
#' @family tasks
198216
#' @export
199-
source_check_tasks_df <- function(path) {
217+
source_check_tasks_df <- function(path, ...) {
200218
name <- names(path)
201219
path <- vcapply(path, check_path_is_pkg_source, USE.NAMES = FALSE)
202220
package <- vcapply(path, get_package_name)
@@ -230,21 +248,29 @@ source_check_tasks_df <- function(path) {
230248
df
231249
}
232250

233-
source_check_tasks_specs <- function(packages, path, aliases) {
251+
source_check_tasks_specs <- function(packages, path, aliases, ...) {
234252
list_of_task_spec(mapply(
235-
function(p, path, a) {
253+
function(
254+
p,
255+
path,
256+
a,
257+
env = NULL,
258+
args = NULL,
259+
build_args = NULL) {
260+
236261
check_task_spec(
237262
alias = a,
238263
package_spec = package_spec_source(name = p, path = path, repos = NULL),
239-
env = DEFAULT_R_CMD_CHECK_VARIABLES,
240-
args = DEFAULT_CHECK_ARGS,
241-
build_args = DEFAULT_BUILD_ARGS
264+
env = env,
265+
args = args,
266+
build_args = build_args
242267
)
243268
},
244269
packages,
245270
path,
246271
aliases,
247272
SIMPLIFY = FALSE,
248-
USE.NAMES = FALSE
273+
USE.NAMES = FALSE,
274+
MoreArgs = list(...)
249275
))
250276
}

R/options.R

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,35 @@
1-
default_tty_tick_interval <- function() {
2-
# refresh interval in milliseconds
3-
getOption(paste0(utils::packageName(), ".tty_tick_interval"), 100) / 1000
4-
}
1+
#' @import options
2+
options::define_options(
3+
"tty refresh interval when reporting results in miliseconds",
4+
tty_tick_interval = 100,
5+
6+
"character vector indicating whether R error should be thrown when issues
7+
are discovered when generating results. \"never\" means that no errors
8+
are thrown. If \"issues\" then errors are emitted only on issues, whereas
9+
\"potential issues\" stands for error on both issues and potential issues.",
10+
error_on = "never",
11+
12+
"character vector indicating which packages should be included in the results.
13+
\"all\" means that all packages are kept. If \"issues\" then only packages
14+
with issues identified, whereas \"potential_issues\" stands for keeping
15+
packages with both \"issues\" and \"potential_issues\".",
16+
keep = "all",
17+
18+
"`logical` indicating whether output directory should be unlinked before
19+
running checks. If `FALSE`, an attempt will me made to restore previous
20+
progress from the same `output`",
21+
restore = NA,
22+
23+
"`logical` indicating whether default R CMD check variables, build args or
24+
check args should be appended whenever custom user ones were provided.",
25+
add_default_configuration = TRUE
26+
)
27+
28+
#' @eval options::as_roxygen_docs()
29+
NULL
30+
31+
#' Checked Options
32+
#' @eval options::as_params()
33+
#' @name options_params
34+
#'
35+
NULL

R/reporter_ansi_tty.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ format_status_line_ansi.default <- function(
7171
report_sleep.reporter_ansi_tty <- function(
7272
reporter,
7373
design,
74-
sleep = default_tty_tick_interval()) {
74+
sleep = options::opt("tty_tick_interval")) {
7575
Sys.sleep(sleep)
7676
}
7777

0 commit comments

Comments
 (0)