alexpghayes / principles

potential outline for tidymodels/principles
https://alexpghayes.github.io/principles/
9 stars 2 forks source link

conversation about model function principles #4

Open topepo opened 6 years ago

topepo commented 6 years ago

This is a start of a draft based on things that have been on my mind for the last few days. It will need to be expanded once we have tidy interface notes/recommendations. It should also be reorganized to be more coherent. This is the model fit analog to topepo/parsnip#41.

<snip>

We distinguish between "top-level"/"user-facing" api's and "low-level"/"computational" api's. The former being the interface between the users of the function (with their needs) and the code that does the estimation/training activities.

When creating model objects, conventions are:

fbchow commented 6 years ago

Ellipses, Keyword vs Non-keyword Arguments

On the topic of ... ellipses, I spent some time digging through code base connecting high-level and low-level APIs and feel as if there must be some minutia or culture of R that I’m missing.

In the context of modeling, what is the best practice for passing a varying number of arguments to a function?

Specifically these 2 cases, the order will affect how you handle “unpacking arguments” within a high-level API:

Is it a best practice to use vars_select to unpack arguments from ... ?

Defensive Programing / Argument Validation

alexpghayes commented 6 years ago

For example, for some modeling method, the function foo would be the top-level api that users experience and some other function (say compute_foo_fit) is used to do the computations. This allows for different interfaces to be used to specify the model that pass common data structures to compute_foo_fit.

And foo should really be a wrapper:

foo <- function(spec_options, fit_options) {
  foo_spec <- create_foo_model_specification(spec_options) # need a naming convention here
  fit(foo_spec, fit_options)
}
topepo commented 6 years ago

In the context of modeling, what is the best practice for passing a varying number of arguments to a function?

Is it a best practice to use ‘vars_select’ to unpack arguments from ... ?

With everyday functions, then ... is the best method. With the tidyverse, we usually use ... for selectors so there are a few different approaches that we are looking at:

topepo commented 6 years ago

@fanny

Also,

It will need to be expanded once we have tidy interface notes/recommendations.

We haven't formally templated out what a tidy model interface looks like (and how it should be implemented). Once we formalize that, it will be much easier to answer questions like the one that you posed.

It's a good question though (and clearly there isn't a definitive answer yet).