Skip to content

Commit

Permalink
Merge pull request #157 from hubverse-org/ak/import-get-hub-fns
Browse files Browse the repository at this point in the history
Import/re-export functions
  • Loading branch information
annakrystalli authored Nov 13, 2024
2 parents d978fdd + fa2bad2 commit 9a3101e
Show file tree
Hide file tree
Showing 25 changed files with 108 additions and 131 deletions.
5 changes: 2 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,12 @@ Imports:
fs,
gh,
hubAdmin (>= 1.0.0),
hubData (>= 1.1.0),
hubUtils (>= 0.1.2),
hubData (>= 1.2.3.9000),
hubUtils (>= 0.2.0.9000),
jsonlite,
jsonvalidate,
lifecycle,
lubridate,
magrittr,
purrr,
rlang,
stringr,
Expand Down
14 changes: 13 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ export(check_tbl_values)
export(check_tbl_values_required)
export(check_valid_round_id)
export(check_valid_round_id_col)
export(coerce_to_hub_schema)
export(combine)
export(create_custom_check)
export(create_hub_schema)
export(expand_model_out_grid)
export(get_tbl_compound_taskid_set)
export(is_any_error)
Expand All @@ -60,6 +62,8 @@ export(opt_check_tbl_col_timediff)
export(opt_check_tbl_counts_lt_popn)
export(opt_check_tbl_horizon_timediff)
export(parse_file_name)
export(read_config)
export(read_config_file)
export(read_model_out_file)
export(submission_tmpl)
export(try_check)
Expand All @@ -69,6 +73,14 @@ export(validate_model_metadata)
export(validate_pr)
export(validate_submission)
export(validate_submission_time)
importFrom(dplyr,"%>%")
importFrom(hubData,coerce_to_hub_schema)
importFrom(hubData,create_hub_schema)
importFrom(hubUtils,get_derived_task_ids)
importFrom(hubUtils,get_hub_file_formats)
importFrom(hubUtils,get_hub_model_output_dir)
importFrom(hubUtils,get_hub_timezone)
importFrom(hubUtils,read_config)
importFrom(hubUtils,read_config_file)
importFrom(lubridate,"%within%")
importFrom(magrittr,"%>%")
importFrom(rlang,"!!!")
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# hubValidations (development version)

* Re-exported functions useful for modelers (#149):
- `hubUtils::read_config()` and `hubUtils::read_config_file()` for reading in hub configuration files.
- `hubData::create_hub_schema()` and `hubData::coerce_to_hub_schema()` for creating and coercing data to the hub schema.

# hubValidations 0.8.0

* Custom checks no longer fail if validation is run outside of the root of the hub (#141)
Expand Down
11 changes: 11 additions & 0 deletions R/imports-hubUtils.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#' @importFrom hubUtils get_hub_file_formats
NULL

#' @importFrom hubUtils get_hub_timezone
NULL

#' @importFrom hubUtils get_hub_model_output_dir
NULL

#' @importFrom hubUtils get_derived_task_ids
NULL
7 changes: 2 additions & 5 deletions R/utils-pipe.R → R/reexport-dplyr.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#' Pipe operator
#'
#' See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details.
#'
#' @name %>%
#' @rdname pipe
#' @keywords internal
#' @name %>%
#' @importFrom dplyr %>%
#' @export
#' @importFrom magrittr %>%
#' @usage lhs \%>\% rhs
#' @param lhs A value or the magrittr placeholder.
#' @param rhs A function call using the magrittr semantics.
#' @return The result of calling `rhs(lhs)`.
Expand Down
7 changes: 7 additions & 0 deletions R/reexport-hubData.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#' @importFrom hubData create_hub_schema
#' @export
hubData::create_hub_schema

#' @importFrom hubData coerce_to_hub_schema
#' @export
hubData::coerce_to_hub_schema
7 changes: 7 additions & 0 deletions R/reexport-hubUtils.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#' @importFrom hubUtils read_config
#' @export
hubUtils::read_config

#' @importFrom hubUtils read_config_file
#' @export
hubUtils::read_config_file
23 changes: 0 additions & 23 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -1,26 +1,3 @@
get_hub_file_formats <- function(hub_path, round_id) {
config_tasks <- hubUtils::read_config(hub_path, "tasks")
round_idx <- hubUtils::get_round_idx(config_tasks, round_id)
file_formats <- config_tasks[["rounds"]][[round_idx]]$file_format
if (!is.null(file_formats)) {
return(file_formats)
}

config_admin <- hubUtils::read_config(hub_path, "admin")
config_admin$file_format
}

get_hub_timezone <- function(hub_path) {
config_admin <- hubUtils::read_config(hub_path, "admin")
config_admin$timezone
}

get_hub_model_output_dir <- function(hub_path) {
config_admin <- hubUtils::read_config(hub_path, "admin")
model_output_dir <- config_admin$model_output_dir
if (is.null(model_output_dir)) "model-output" else model_output_dir
}

get_file_target_metadata <- function(hub_path, file_path) {
round_config <- get_file_round_config(file_path, hub_path)

Expand Down
3 changes: 3 additions & 0 deletions man/check_tbl_col_types.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/expand_model_out_grid.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/opt_check_tbl_col_timediff.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/opt_check_tbl_horizon_timediff.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions man/pipe.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/read_model_out_file.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions man/reexports.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/validate_model_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/validate_pr.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/validate_submission.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions tests/testthat/_snaps/check_tbl_value_col.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
Code
check_tbl_value_col(tbl, round_id, file_path, hub_path)
Output
<error/check_failure>
Error:
! Values in column `value` are not all valid with respect to modeling task config. Values 196.83, 367.89, 244.85, 427.975, 310.9, 499.9, 394.8, 461.85, 629.7, 534.6, 599.75, 727.5, 669.7, 725.562456357284, 801.689162048122, 800.239938093011, 915.5, 949.59, ..., 2775.56600111008, and 2139.07 cannot be coerced to expected data type "integer" for output type "quantile".
<message/check_success>
Message:
Values in column `value` all valid with respect to modeling task config.

# check_tbl_value_col errors correctly

Expand All @@ -32,7 +32,7 @@
Output
<error/check_failure>
Error:
! Values in column `value` are not all valid with respect to modeling task config. Value "fail" cannot be coerced to expected data type "integer" for output type "quantile".Values in column `value` are not all valid with respect to modeling task config. Values "196.83", "244.85", "310.9", "499.9", "394.8", "461.85", "629.7", "534.6", "599.75", "727.5", "669.7", "725.562456357284", "801.689162048122", "800.239938093011", "915.5", "949.59", "938.67", "962.03", ..., "2775.56600111008", and "2139.07" cannot be coerced to expected data type "integer" for output type "quantile".Values in column `value` are not all valid with respect to modeling task config. Value -6 is smaller than allowed minimum value 0 for output type "quantile".
! Values in column `value` are not all valid with respect to modeling task config. Value "fail" cannot be coerced to expected data type "integer" for output type "quantile".Values in column `value` are not all valid with respect to modeling task config. Value -6 is smaller than allowed minimum value 0 for output type "quantile".

# Ignoring derived_task_ids in check_tbl_value_col works

Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/_snaps/check_tbl_value_col_sum1.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
$ message : chr "Values in `value` column do not sum to 1 for all unique task ID value combination of pmf\n output types. \n "| __truncated__
$ trace : NULL
$ parent : NULL
$ where : chr "umass_ens/2023-05-08-umass_ens.csv"
$ where : chr "umass-ens/2023-05-08-umass-ens.csv"
$ error_tbl : tibble [1 x 5] (S3: tbl_df/tbl/data.frame)
..$ forecast_date: Date[1:1], format: "2023-05-08"
..$ horizon : int 2
Expand All @@ -36,7 +36,7 @@
$ message : chr "Values in `value` column do not sum to 1 for all unique task ID value combination of pmf\n output types. \n "| __truncated__
$ trace : NULL
$ parent : NULL
$ where : chr "umass_ens/2023-05-08-umass_ens.csv"
$ where : chr "umass-ens/2023-05-08-umass-ens.csv"
$ error_tbl : tibble [1 x 5] (S3: tbl_df/tbl/data.frame)
..$ forecast_date: Date[1:1], format: "2023-05-08"
..$ horizon : int 2
Expand All @@ -54,7 +54,7 @@
Output
List of 5
$ message : chr "Values in `value` column do sum to 1 for all unique task ID value combination of pmf\n output types. \n "
$ where : chr "umass_ens/2023-05-08-umass_ens.csv"
$ where : chr "umass-ens/2023-05-08-umass-ens.csv"
$ error_tbl : NULL
$ call : chr "check_tbl_value_col_sum1"
$ use_cli_format: logi TRUE
Expand Down
37 changes: 0 additions & 37 deletions tests/testthat/_snaps/utils.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,3 @@
# get_hub_file_formats works

Code
get_hub_file_formats(hub_path = system.file("testhubs/simple", package = "hubValidations"),
round_id = "2022-10-08")
Output
[1] "csv" "parquet" "arrow"

---

Code
get_hub_file_formats(hub_path = system.file("testhubs/flusight", package = "hubUtils"),
round_id = "2023-01-30")
Output
[1] "csv" "parquet" "arrow"

# get_hub_timezone works

Code
get_hub_timezone(hub_path = system.file("testhubs/simple", package = "hubValidations"))
Output
[1] "US/Eastern"

# get_hub_model_output_dir works

Code
get_hub_model_output_dir(hub_path = system.file("testhubs/simple", package = "hubValidations"))
Output
[1] "model-output"

---

Code
get_hub_model_output_dir(hub_path = system.file("testhubs/flusight", package = "hubUtils"))
Output
[1] "forecasts"

# get_file_round_id works

Code
Expand Down
16 changes: 6 additions & 10 deletions tests/testthat/_snaps/validate_model_data.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,12 @@
..$ call : chr "check_tbl_colnames"
..$ use_cli_format: logi TRUE
..- attr(*, "class")= chr [1:5] "check_success" "hub_check" "rlang_message" "message" ...
$ col_types :List of 6
..$ message : chr "Column data types do not match hub schema. \n `output_type_id` should be \"character\" not \"double\"."
..$ trace : NULL
..$ parent : NULL
$ col_types :List of 4
..$ message : chr "Column data types match hub schema. \n "
..$ where : chr "hub-ensemble/2023-05-08-hub-ensemble.parquet"
..$ call : chr "check_tbl_col_types"
..$ use_cli_format: logi TRUE
..- attr(*, "class")= chr [1:5] "check_failure" "hub_check" "rlang_error" "error" ...
..- attr(*, "class")= chr [1:5] "check_success" "hub_check" "rlang_message" "message" ...
$ valid_vals :List of 5
..$ message : chr "`tbl` contains valid values/value combinations. \n "
..$ where : chr "hub-ensemble/2023-05-08-hub-ensemble.parquet"
Expand All @@ -201,14 +199,12 @@
..$ call : chr "check_tbl_values_required"
..$ use_cli_format: logi TRUE
..- attr(*, "class")= chr [1:5] "check_success" "hub_check" "rlang_message" "message" ...
$ value_col_valid :List of 6
..$ message : chr "Values in column `value` are not all valid with respect to modeling task config. \n Values 196.83, 367.89, 244"| __truncated__
..$ trace : NULL
..$ parent : NULL
$ value_col_valid :List of 4
..$ message : chr "Values in column `value` all valid with respect to modeling task config. \n "
..$ where : chr "hub-ensemble/2023-05-08-hub-ensemble.parquet"
..$ call : chr "check_tbl_value_col"
..$ use_cli_format: logi TRUE
..- attr(*, "class")= chr [1:5] "check_failure" "hub_check" "rlang_error" "error" ...
..- attr(*, "class")= chr [1:5] "check_success" "hub_check" "rlang_message" "message" ...
$ value_col_non_desc:List of 5
..$ message : chr "Values in `value` column are non-decreasing as output_type_ids increase for all unique task ID\n value/outpu"| __truncated__
..$ where : chr "hub-ensemble/2023-05-08-hub-ensemble.parquet"
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-check_tbl_value_col_sum1.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
test_that("check_tbl_value_col_sum1 works", {
hub_path <- system.file("testhubs/flusight", package = "hubUtils")
file_path <- "umass_ens/2023-05-08-umass_ens.csv"
file_path <- "umass-ens/2023-05-08-umass-ens.csv"
round_id <- "2023-05-08"
tbl <- hubValidations::read_model_out_file(file_path, hub_path)
expect_snapshot(
Expand All @@ -10,7 +10,7 @@ test_that("check_tbl_value_col_sum1 works", {

test_that("check_tbl_value_col_sum1 errors correctly", {
hub_path <- system.file("testhubs/flusight", package = "hubUtils")
file_path <- "umass_ens/2023-05-08-umass_ens.csv"
file_path <- "umass-ens/2023-05-08-umass-ens.csv"
round_id <- "2023-05-08"
tbl <- hubValidations::read_model_out_file(file_path, hub_path)
tbl$value[1] <- 0.1
Expand Down
Loading

0 comments on commit 9a3101e

Please sign in to comment.