Skip to content

Does the recommendation against using plan inside packages also prohibit default values? #274

@HughParsonage

Description

@HughParsonage

Thank you for this wonderful package. I have a question regarding the documentation in ?plan:

For package developers

Please refrain from modifying the future strategy inside your packages / functions, i.e. do not call plan() in your code. Instead, leave the control on what backend to use to the end user. This idea is part of the core philosophy of the future framework - as a developer you can never know what future backends the user have access to. Moreover, by not making any assumptions about what backends are available, your code will also work automatically will any new backends developed after you wrote your code.

My summary of this philosophy is that a package should never wrest control of plan from the end-user.

What is your advice or philosophy about using arguments to control plan and having default values? Essentially, is it okay to use plan("multiprocess"), provided "multisession" can be changed and doesn't conflict with an already established plan? For example, would it be acceptable within the future framework to have a default setting within a package function which uses the following logic?

foo <- function(..., planner = NULL) {
  if (is.null(planner)) {
    if (plan_is_already_invoked()) {
      NULL  # keep using whatever was running
    } else {
      plan(multiprocess)
    }
  } else {
    plan(planner)
  }
  <rest of function>
}

That is, if no planner is supplied to foo, use whatever is running; or, if none are, use "multiprocess".

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions