-
Notifications
You must be signed in to change notification settings - Fork 4
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
Writing custom check functions vignette #127
Open
annakrystalli
wants to merge
14
commits into
main
Choose a base branch
from
ak/custom-fn-dev-article/121
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
859b878
Add dependency section deps
annakrystalli 1b9b943
Update navbar drop down topics
annakrystalli 9023f5f
add step to link to dev version of docs if appropriate
annakrystalli 0989285
Separate section on caller env object into child
annakrystalli a2203e2
Commit draft
annakrystalli c1c1443
Merge branch 'main' into ak/custom-fn-dev-article/121
annakrystalli 646186e
Add child sections on managing custom fns & additional dependencies. …
annakrystalli da3e652
Additional info
annakrystalli 1d33cf0
rename custom-functions article to deploying-custom-functions
annakrystalli dc6bfa8
skip submission window check
annakrystalli ca693a2
Appease linter!
annakrystalli 28e9589
Update NEWS
annakrystalli 91b10f3
Use Rmd instead of qmd
annakrystalli 593bc6d
correct netlify preview GA dev status determination step
annakrystalli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -277,7 +277,10 @@ test_that("(#123) check_tbl_values_required works with all optional output types | |
) | ||
# Ensure that req_vals check is the only one that fails | ||
expect_snapshot( | ||
check_for_errors(validate_submission(hub_path, file_path)), | ||
check_for_errors(validate_submission( | ||
hub_path, file_path, | ||
skip_submit_window_check = TRUE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just fixing an oversight in a previously added test that was now returning a submission window check error |
||
)), | ||
error = TRUE | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
### Deploying custom functions as a package | ||
|
||
To deploy custom functions managed as a package in `src/validations`, you can use the `pkg` configuration property in the `validations.yml` file to specify the package namespace. | ||
|
||
For example, if you have created a simple package in `src/validations/` with a `cstm_check_tbl_example.R` script containing the specification of an `cstm_check_tbl_example()` function in `src/validations/R`, you can use the following configuration in your `validation.yml` file to source the function from the installed `validations` package namespace: | ||
|
||
``` | ||
default: | ||
validate_model_data: | ||
custom_check: | ||
fn: "cstm_check_tbl_example" | ||
pkg: "validations" | ||
``` | ||
|
||
To ensure the package (and any additional dependencies it depends on) is installed and available during validation, you must add the package to the `setup-r-dependencies` step in the `hubverse-actions` `validate-submission.yaml` GitHub Action workflow of your hub like so: | ||
|
||
```yaml | ||
- uses: r-lib/actions/setup-r-dependencies@v2 | ||
with: | ||
packages: | | ||
any::hubValidations | ||
any::sessioninfo | ||
local::./src/validations | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
|
||
## Available dependencies | ||
|
||
**All `hubValidations` exported functions are available** for use in your custom check functions as well as functions from hubverse packages **`huUtils`**, **`hubAdmin`** and **`hubData`**. | ||
|
||
```{r, echo=FALSE} | ||
get_deps <- function(pkg) { | ||
suppressMessages(pak::pkg_deps(pkg)) | ||
} | ||
memoise_pkg_deps <- memoise::memoise(get_deps) | ||
pkgs <- memoise_pkg_deps(".")[, c("package", "version")] | ||
``` | ||
|
||
In addition, **functions in packages from the `hubValidations` dependency tree are also generally available**, both locally (once `hubValidations` is installed) and in the hubverse `validate-submission` GitHub Action. | ||
|
||
Functions from these packages can be used in your custom checks without specifying them as additional dependencies. | ||
|
||
```{r, echo=FALSE} | ||
pkgs[order(pkgs$package), ] |> | ||
DT::datatable() | ||
``` | ||
|
||
|
||
## Additional dependencies | ||
|
||
If any custom functions you are deploying depend on additional packages, you will need to ensure these packages are available during validation. | ||
|
||
The simplest way to ensure they are available is to edit the `setup-r-dependencies` step in the `hubverse-actions` [`validate-submission.yaml`](https://github.com/hubverse-org/hubverse-actions/blob/main/validate-submission/validate-submission.yaml) GitHub Action workflow of your hub and add any additional dependency to the `packages` field list. | ||
|
||
In the following pseudo example we add `additionalPackage` package to the list of standard dependencies: | ||
|
||
```yaml | ||
- uses: r-lib/actions/setup-r-dependencies@v2 | ||
with: | ||
packages: | | ||
any::hubValidations | ||
any::sessioninfo | ||
any::additionalPackage | ||
``` | ||
|
||
Note that this ensures the additional dependency is available during validation on GitHub but does not guarantee it will be installed locally for hub administrators or submitting teams. Indeed such missing dependencies could lead to execution errors in custom checks when running `validate_submission()` locally. | ||
|
||
You could use documentation, like your hub's README to communicate additional required dependencies for validation to submitting teams. Even better, you could add a check to the top of your function to catch missing dependencies and provide a helpful error message to the user. | ||
|
||
```{r, eval=FALSE} | ||
if (!(requireNamespace("additionalPackage"))) { | ||
stop( | ||
"Package 'additionalPackage' must be installed to run the full validation check. | ||
Please install and try again." | ||
) | ||
} | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Each of the `validate_*()` functions contain a number of standard objects in their call environment which are passed automatically to arguments with the same name and therefore do not need including but can be overridden through a function's `args` configuration during deployment. | ||
|
||
The exact set of objects available to arguments depend on `validate_*()` calling function: | ||
|
||
- **`validate_model_file`:** | ||
- `file_path`: character string of path to file being validated relative to the `model-output` directory. | ||
- `hub_path`: character string of path to hub. | ||
- `round_id`: character string of `round_id` | ||
- `file_meta`: named list containing `round_id`, `team_abbr`, `model_abbr` and `model_id` details. | ||
- **`validate_model_data`:** | ||
- `tbl`: a tibble of the model output data being validated. | ||
- `tbl_chr`: a tibble of the model output data being validated with all columns coerced to character type. | ||
- `file_path`: character string of path to file being validated relative to the `model-output` directory. | ||
- `hub_path`: character string of path to hub. | ||
- `round_id`: character string of `round_id` | ||
- `file_meta`: named list containing `round_id`, `team_abbr`, `model_abbr` and `model_id` details. | ||
- `round_id_col`: character string of name of `tbl` column containing `round_id` information. | ||
- `output_type_id_datatype`: character string. The value of the `output_type_id_datatype` argument. This value is useful in functions like `hubData::create_hub_schema()` or `hubValidations::expand_model_out_grid()` to set the data type of `output_type_id` column. | ||
- `derived_task_ids`: character vector or `NULL`. The value of the `derived_task_ids` argument, i.e. the names of task IDs whose values depend on other task IDs. | ||
- **`validate_model_metadata`:** | ||
- `file_path`: character string of path to file being validated relative to the `model-output` directory. | ||
- `hub_path`: character string of path to hub. | ||
- `round_id`: character string of `round_id` | ||
- `file_meta`: named list containing `round_id`, `team_abbr`, `model_abbr` and `model_id` details. | ||
|
||
The `args` configuration can be used to override objects from the caller environment as well as defaults during deployment. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
These changes fix broken dev previews URLs resulting from the fact we've got both release and dev versions of docs now