tiernanmartin / drakepkg

Demonstrate A Drake Workflow Package
Other
29 stars 5 forks source link

plans as data vs functions #3

Closed wlandau closed 5 years ago

wlandau commented 6 years ago

I have been thinking about your question from https://github.com/ropensci/drake/issues/471#issuecomment-407489404, and I feel more strongly about distributing plans as functions rather than datasets. The functions I have in mind would have all relevant calls to drake_plan(), evaluate_plan(), bind_plans(), etc. This encourages good practice since the generating code of the plan is important to have on hand, and it gives you flexibility for generating different versions of the same plan. Also, users of drakepkg can see how your plans are generated, and it could help them generate their own plans.

#' @title Get a simple plan
#' @description Generate the plan from `drake_plan()` and friends.
#' @export
#' @return a `drake` plan
#' @param n number of replicates
get_simple_plan <- function(n = 2){
  subplan1 <- drake_plan(x = a__) %>%
    evaluate_plan(wildcard = "a__", values = seq_len(n))
  subplan2 <- drake_plan(y = b__) %>%
    evaluate_plan(wildcard = "b__", values = seq_len(n))
  bind_plans(subplan1, subplan2)
}
tiernanmartin commented 6 years ago

Good points! I agree completely.

I'm working on a deadline project right now but as soon as I'm finished with that I'll convert plan_example into a function and change the package documentation accordingly.

Thanks!

tiernanmartin commented 5 years ago

I have adopted this approach and found that it works way better than the old one.

The package has been updated accordingly.