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

Vignette on the add_*/remove_*/update_*, adjust_* and tidy functions #274

Merged
merged 6 commits into from
Jan 28, 2024

Conversation

rachlobay
Copy link
Contributor

Here's a vignette that goes over how to use the add/remove/update, adjust and tidy functions that were recently added to the package.

@rachlobay rachlobay requested a review from dajmcdon as a code owner December 2, 2023 03:24
Copy link
Contributor

@dajmcdon dajmcdon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made some suggestions for simplicity. Please try to apply the same throughout the vignette (I suspect I got many, but not all).

Once you're done, you can merge.

library(recipes)
```

In this vignette, we will state the main goal of the add/update/remove and adjust functions and describe what part of the processing each function is intended for. We will then demonstrate how to use the sets of add/update/remove functions, followed by the adjust functions, and end with a brief discussion on the tidy methods for recipe and frosting objects.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add carriage returns so that this line breaks at 80 characters? Makes reviewing and editing much easier. Same for much of the below.


## Main goal of the add/update/remove and adjust functions

The primary goal of the update and adjust functions is to allow the user to modify a `step`, `layer`, `epi_recipe`, `frosting`, or a part of an `epi_workflow` so that they do not have to create a new object each time they wish to make a change to the pre-processing, fitting, or post-processing.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for functions, it's better to end them with open+close parenthesis. I think here, these are all "objects", so it doesn't need that, but maybe clearer then to add "objects" in the sentence.


| | Add/update/remove functions | adjust functions |
|----------------------------|------------------------------------------------------------|---------------------|
| Pre-processing | `add_epi_recipe`, `update_epi_recipe`, `remove_epi_recipe` | `adjust_epi_recipe` |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more functions.


We can observe that `wf` is no longer an `epi_workflow` and a `workflow`. It has been demoted to only a `workflow`. While all `epi_workflow`s are `workflow`s, not all `workflow`s are `epi_workflow`s, meaning that there may be compatibility issues and limitations to the tools that may be used from the `epipredict` package on a plain `workflow` object.

Now, while we checked what happens to the above `epi_recipe` if we remove it, note that we did not actually store that change to `wf` (using the assignment operator `<-`). Hence, our `epi_workflow` remains unchanged.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Now, while we checked what happens to the above `epi_recipe` if we remove it, note that we did not actually store that change to `wf` (using the assignment operator `<-`). Hence, our `epi_workflow` remains unchanged.
Now, while we checked what happens to the above `epi_recipe` if we remove it, note that we did not actually store that change to `wf`.


The primary goal of the update and adjust functions is to allow the user to modify a `step`, `layer`, `epi_recipe`, `frosting`, or a part of an `epi_workflow` so that they do not have to create a new object each time they wish to make a change to the pre-processing, fitting, or post-processing.

In the context of pre-processing, the goal of the update functions is to add/remove/update an `epi_recipe` or a step in it. For this, we have `add_epi_recipe`, `update_epi_recipe`, and `remove_epi_recipe` to add/update/remove an entire `epi_recipe` in an `epi_workflow` as well as `adjust_epi_recipe` to adjust a particular step in an `epi_recipe` or `epi_workflow` by the step number or name. For a model, one may `add_model`, `update_model`, or `remove_model` in an `epi_workflow`. For post-processing, where the goal is to update a frosting object or a layer in it, we have `add_frosting`, `remove_frosting`, and `update_frosting` to add/update/remove an entire `frosting` object in an `epi_workflow` as well as `adjust_frosting` to adjust a particular layer in a `frosting` or `epi_workflow` by its number or name. A summary of the function uses by processing step is shown by the following table:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example:

Suggested change
In the context of pre-processing, the goal of the update functions is to add/remove/update an `epi_recipe` or a step in it. For this, we have `add_epi_recipe`, `update_epi_recipe`, and `remove_epi_recipe` to add/update/remove an entire `epi_recipe` in an `epi_workflow` as well as `adjust_epi_recipe` to adjust a particular step in an `epi_recipe` or `epi_workflow` by the step number or name. For a model, one may `add_model`, `update_model`, or `remove_model` in an `epi_workflow`. For post-processing, where the goal is to update a frosting object or a layer in it, we have `add_frosting`, `remove_frosting`, and `update_frosting` to add/update/remove an entire `frosting` object in an `epi_workflow` as well as `adjust_frosting` to adjust a particular layer in a `frosting` or `epi_workflow` by its number or name. A summary of the function uses by processing step is shown by the following table:
In the context of pre-processing, the goal of the update functions is to add/remove/update an
`epi_recipe` or a step in it. For this, we have `add_epi_recipe()`, `update_epi_recipe()`, and `remove_epi_recipe()` to alter an entire `epi_recipe` in an `epi_workflow` as well as
`adjust_epi_recipe()` to alter the arguments to a particular step in an `epi_recipe` or `epi_workflow` by the step number or name.
For a model, one may `add_model()`, `update_model()`, or `remove_model()` in an `epi_workflow`.
For post-processing, where the goal is to update a frosting object or a layer in it, we have `add_frosting()`, `remove_frosting()`, and `update_frosting()` to alter the entire `frosting` object in an `epi_workflow` as
well as `adjust_frosting()` to alter the arguments to a particular layer in a `frosting` or `epi_workflow` by
its number or name.
A summary of the function uses by processing step is shown by the following table:


A longer approach to achieve the same end is to use `remove_epi_recipe` to remove the old recipe and then `add_epi_recipe` to add the new one. Under the hood, the `update_epi_recipe` function operates in this way.

The `add_epi_recipe` and `remove_epi_recipe` functions offload to the `workflows` versions of the functions (`workflows::add_recipe()` and `workflows::remove_recipe()`) as much as possible. The main reason for using the `epipredict` version is so that we ensure that we do not lose the `epi_workflow` class.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer package names to go in curly braces. (Good use of paren on the function names here.)

Suggested change
The `add_epi_recipe` and `remove_epi_recipe` functions offload to the `workflows` versions of the functions (`workflows::add_recipe()` and `workflows::remove_recipe()`) as much as possible. The main reason for using the `epipredict` version is so that we ensure that we do not lose the `epi_workflow` class.
The `add_epi_recipe()` and `remove_epi_recipe()` functions offload to the `{workflows}` versions of the
functions as much as possible. The main reason for using the `{epipredict}` version is so that we ensure
that we retain the `epi_workflow` class.


```{r}
wf %>% class() # class before
workflows::remove_recipe(wf) %>% class() # class after removing recipe using workflows function
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
workflows::remove_recipe(wf) %>% class() # class after removing recipe using workflows function
workflows::remove_recipe(wf) %>% class() # class after removing recipe using workflows function

Comment on lines +175 to +176
workflows::extract_preprocessor(wf) # step_epi_ahead is the third step in r2
tidy(workflows::extract_preprocessor(wf)) # tidy tibble summary of r2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
workflows::extract_preprocessor(wf) # step_epi_ahead is the third step in r2
tidy(workflows::extract_preprocessor(wf)) # tidy tibble summary of r2
extract_preprocessor(wf) # step_epi_ahead is the third step in r2
tidy(extract_preprocessor(wf)) # tidy tibble summary of r2

```{r}
wf <- wf %>% adjust_epi_recipe(which_step = 2, lag = c(0, 1, 7, 14, 21))

workflows::extract_preprocessor(wf)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
workflows::extract_preprocessor(wf)
extract_preprocessor(wf)

```{r}
r2 <- adjust_epi_recipe(r2, which_step = 2, lag = 0:21)

workflows::extract_preprocessor(wf)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
workflows::extract_preprocessor(wf)
extract_preprocessor(wf)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'm going to keep the workflows:: for now because it's a quick and clear way to indicate what functions I used are from that package & I think it's good to lay that out somewhere (because otherwise it can be hard to tell for a beginner which functions are from that package and which are from ours - because it's not exceedingly common).

@rachlobay rachlobay merged commit d46e0c5 into main Jan 28, 2024
2 checks passed
@dajmcdon dajmcdon linked an issue Mar 6, 2024 that may be closed by this pull request
@dajmcdon dajmcdon deleted the update-vignette branch June 18, 2024 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Vignette that demonstrates the update & adjust functions
2 participants