Skip to content

Commit

Permalink
generic step_run_code(), closes #1, closes #3
Browse files Browse the repository at this point in the history
- New `step_run_code()` to run arbitrary code. If the code is a call with the `pkg::fun()`, notation, pkg is installed if missing (#1, #3). `step_run_covr()` remains for compatibility but is scheduled for removal.
  • Loading branch information
krlmlr committed Jun 5, 2017
1 parent 7f01b39 commit bade121
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Collate:
'run.R'
'stage.R'
'steps-base.R'
'steps-code.R'
'steps-covr.R'
'steps-git.R'
'steps-pkgdown.R'
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export(step_build_pkgdown)
export(step_hello_world)
export(step_install_ssh_keys)
export(step_push_deploy)
export(step_run_code)
export(step_run_covr)
export(step_test_ssh)
importFrom(R6,R6Class)
Expand Down
31 changes: 31 additions & 0 deletions R/steps-code.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
RunCode <- R6Class(
"RunCode", inherit = TicStep,

public = list(
initialize = function(call) {
call <- substitute(call)
private$call <- call
},

run = function() {
eval(private$call, envir = baseenv())
},

prepare = function() {
func_name <- private$call[[1]]
if (is.call(func_name) && func_name[[1]] == quote(`::`)) {
pkg_name <- as.character(func_name[[2]])
if (!requireNamespace(pkg_name, quietly = TRUE)) {
install.packages(pkg_name)
}
}
}
),

private = list(
call = NULL
)
)

#' @export
step_run_code <- RunCode$new

0 comments on commit bade121

Please sign in to comment.