Skip to content

Commit

Permalink
vapply > purrr::map to not force purrr installation during CI setup
Browse files Browse the repository at this point in the history
  • Loading branch information
pat-s committed Jul 13, 2020
1 parent 4af7abb commit 1228a73
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions R/stage.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,42 @@ TicStage <- R6Class( # nolint
private$stage_name <- stage_name
private$steps <- list()
},

add_step = function(step, code) {
self$add_task(
run = step$run, check = step$check, prepare = step$prepare,
name = code
)
},

add_task = function(run, check = NULL, prepare = NULL, name = NULL) {
step <- list(
run = run,
check = check %||% function() TRUE,
prepare = prepare %||% function() {}, # nolint
name = name %||% "<unknown task>"
)
existing_steps <- purrr::map_chr(private$steps, ~ .x$name)
existing_steps <- vapply(private$steps, function(.x) .x$name,
FUN.VALUE = character(1)
)
if (name %in% existing_steps) {
invisible(self)
} else {
private$steps <- c(private$steps, list(step))
invisible(self)
}
},

is_empty = function() {
is_empty(private$steps)
},

reset = function() {
private$steps <- list()
},

prepare_all = function() {
# We don't necessarily require a DESCRIPTION file.
# Steps that need one can check beforehand and warn the user with a
# legible message.
lapply(private$steps, private$prepare_one)
invisible()
},

run_all = function() {
success <- TRUE
for (step in private$steps) {
Expand All @@ -56,7 +52,6 @@ TicStage <- R6Class( # nolint
}
}
},

print = function(..., omit_if_empty = FALSE) {
if (omit_if_empty && length(private$steps) == 0) {
return()
Expand All @@ -70,11 +65,9 @@ TicStage <- R6Class( # nolint
}
}
),

private = list(
stage_name = NULL,
steps = NULL,

prepare_one = function(step) {
if (identical(body(step$prepare), body(TicStep$public_methods$prepare))) {
return()
Expand All @@ -95,7 +88,6 @@ TicStage <- R6Class( # nolint

invisible()
},

run_one = function(step) {
if (!isTRUE(step$check())) {
ci_cat_with_color(
Expand Down

0 comments on commit 1228a73

Please sign in to comment.