Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plans as functions #999

Closed
3 tasks done
odgersn opened this issue Aug 29, 2019 · 3 comments
Closed
3 tasks done

Plans as functions #999

odgersn opened this issue Aug 29, 2019 · 3 comments

Comments

@odgersn
Copy link

odgersn commented Aug 29, 2019

Prework

Question

I'm trying to wrap my head around how best to implement plans as functions, with a view towards encapsulating these functions in a package. I know it's really pretty straightforward, but I guess I'd like confirmation about the "correct" way to handle how a function's arguments interact with the plan inside a function. The example functions that I have seen so far do not have arguments. Consider the following basic example:

library(drake)
library(raster)

pl_raster <- function(a, b) {
  drake_plan(
    r = raster(x = runif(!!a * !!b),
               nrows = !!a,
               ncols = !!b)
  )
}

pl_raster(5, 5)

# # A tibble: 1 x 2
#   target command                                       
#   <chr>  <expr>                                        
# 1 r      raster(x = runif(5 * 5), nrows = 5, ncols = 5)

Arguments a and b identify the number of rows and columns in the raster r, respectively. They're unquoted into the plan so that their values are substituted properly. I suppose that this is the "right" way to do it. It just seems like you could quickly accumulate a large number of arguments if you were functionising a large plan that has lots of inputs.

@wlandau
Copy link
Member

wlandau commented Aug 30, 2019

I love this question, re: #994 and function oriented workflows.

Yes, this is exactly how I recommend encapsulating a plan inside a function. True, the function may accrue too many arguments if you are not careful, but I think this is a matter of defining the right priorities. What are the most important levers to tweak here? Personally, I find it particularly helpful to scale down / in for a test run and scale up / out for production. Maybe users of your package want to experiment with their own set of models. These are the arguments I would think about exposing.

Also, since you are developing a package with a plan, I recommend having a look at expose_imports() so that drake can detect the other functions in your package.

@wlandau wlandau closed this as completed Aug 30, 2019
@odgersn
Copy link
Author

odgersn commented Aug 30, 2019

Thanks Will. Just to be clear: I'd need to call expose_imports() before I call drake_config() or make() in the script that makes use of my package functions, correct? That's what ?expose_imports() seems to imply.

@wlandau
Copy link
Member

wlandau commented Aug 30, 2019

Yes, exactly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants