-
Notifications
You must be signed in to change notification settings - Fork 10
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
Conversation
There was a problem hiding this 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.
vignettes/update.Rmd
Outdated
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. |
There was a problem hiding this comment.
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.
vignettes/update.Rmd
Outdated
|
||
## 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. |
There was a problem hiding this comment.
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.
vignettes/update.Rmd
Outdated
|
||
| | Add/update/remove functions | adjust functions | | ||
|----------------------------|------------------------------------------------------------|---------------------| | ||
| Pre-processing | `add_epi_recipe`, `update_epi_recipe`, `remove_epi_recipe` | `adjust_epi_recipe` | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more functions.
vignettes/update.Rmd
Outdated
|
||
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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`. |
vignettes/update.Rmd
Outdated
|
||
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example:
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: |
vignettes/update.Rmd
Outdated
|
||
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. |
There was a problem hiding this comment.
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.)
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
workflows::remove_recipe(wf) %>% class() # class after removing recipe using workflows function | |
workflows::remove_recipe(wf) %>% class() # class after removing recipe using workflows function |
workflows::extract_preprocessor(wf) # step_epi_ahead is the third step in r2 | ||
tidy(workflows::extract_preprocessor(wf)) # tidy tibble summary of r2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
workflows::extract_preprocessor(wf) | |
extract_preprocessor(wf) |
```{r} | ||
r2 <- adjust_epi_recipe(r2, which_step = 2, lag = 0:21) | ||
|
||
workflows::extract_preprocessor(wf) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
workflows::extract_preprocessor(wf) | |
extract_preprocessor(wf) |
There was a problem hiding this comment.
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).
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.