-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #494 from ropensci/drake_plan_class
Use an S3 "drake_plan" class
- Loading branch information
Showing
10 changed files
with
123 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#' @title Mark a data frame as a `drake` workflow plan | ||
#' @description Used for pretty printing only (coming soon). | ||
#' You do not actually have to mark plans as such. | ||
#' You can keep them as ordinary data frames. | ||
#' @export | ||
#' @keywords internal | ||
#' @param x object to mark as a `drake` plan | ||
#' @param ... other arguments to the method | ||
#' @examples | ||
#' plan <- list(target = "x", command = "get_data()") | ||
#' class(plan) | ||
#' plan <- as_drake_plan(plan) | ||
#' class(plan) | ||
as_drake_plan <- function(x, ...){ | ||
UseMethod("as_drake_plan") | ||
} | ||
|
||
as_drake_plan_ <- function(x, ...){ | ||
tibble::new_tibble(x, ..., subclass = "drake_plan") | ||
} | ||
|
||
#' @export | ||
`[.drake_plan` <- function(...){ | ||
as_drake_plan_(NextMethod()) | ||
} | ||
|
||
#' @export | ||
#' @rdname as_drake_plan | ||
as_drake_plan.data.frame <- as_drake_plan_ | ||
|
||
#' @export | ||
#' @rdname as_drake_plan | ||
as_drake_plan.list <- as_drake_plan_ | ||
|
||
#' @export | ||
#' @rdname as_drake_plan | ||
as_drake_plan.tbl_df <- as_drake_plan_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
drake_plan_call <- function(plan){ | ||
target_calls <- purrr::pmap(plan, drake_target_call) %>% | ||
setNames(plan$target) | ||
as.call(c(quote(drake_plan), target_calls)) | ||
} | ||
|
||
drake_target_call <- function(...){ | ||
args <- list(...)[drake_plan_columns()] %>% | ||
select_valid() | ||
target <- parse(text = args$target)[[1]] | ||
args$target <- NULL | ||
if (!is.null(args$command) && is.character(args$command)){ | ||
args$command <- parse(text = args$command)[[1]] | ||
} | ||
if (!is.null(args$trigger) && is.character(args$trigger)){ | ||
args$trigger <- parse(text = args$trigger)[[1]] | ||
} | ||
if (!identical(names(args), "command")){ | ||
args$command <- as.call(c(quote(target), args)) | ||
} | ||
args$command | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters