-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from ThomUK/v0.1.2
V0.1.2 merge community contribution and further useability improvements.
- Loading branch information
Showing
15 changed files
with
235 additions
and
89 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export("%>%") | ||
export(spcr_check_dataset_is_complete) | ||
export(spcr_make_data_bundle) | ||
export(spcr_make_report) | ||
importFrom(magrittr,"%>%") | ||
importFrom(utils,browseURL) |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#' Check all required data items are provided | ||
#' | ||
#' @param report_config dataframe. The report config detailing required report items | ||
#' @param measure_data list. The data items to check | ||
#' | ||
#' @return logical | ||
#' @export | ||
#' | ||
spcr_check_dataset_is_complete <- function(report_config, measure_data) { | ||
|
||
required_data <- report_config |> | ||
dplyr::distinct(ref, measure_name, aggregation) | ||
|
||
supplied_data <- measure_data |> | ||
dplyr::bind_rows(.id = "aggregation") |> | ||
dplyr::select(ref, measure_name, aggregation) | ||
|
||
missing <- dplyr::setdiff(required_data, supplied_data) | ||
|
||
# build an error message if there are missing data items | ||
assertthat::assert_that( | ||
nrow(missing) == 0, | ||
msg = paste0( | ||
"spcr_check_dataset_is_complete: Data is missing for ", | ||
nrow(missing), | ||
" report items. The first is ref ", | ||
missing[1,][["ref"]], | ||
", ", | ||
missing[1,][["measure_name"]], | ||
", ", | ||
missing[1,][["aggregation"]], | ||
"ly." | ||
) | ||
) | ||
|
||
return(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
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
measure_data <- list( | ||
week = tibble::tibble( | ||
ref = c("1", "2", "3"), | ||
measure_name = c("M1", "M2", "M3"), | ||
comment = c("comment", "comment", "comment"), | ||
`43836` = c(1, 3.2, 0.5), | ||
`43843` = c(2, 4.2, 0.6), | ||
`43850` = c(1, 3.2, 0.5), | ||
`43857` = c(2, 4.2, 0.6), | ||
`43864` = c(1, 3.2, 0.5), | ||
`43871` = c(2, 4.2, 0.6), | ||
`43878` = c(1, 3.2, 0.5), | ||
`43885` = c(2, 4.2, 0.6), | ||
`43892` = c(1, 3.2, 0.5), | ||
`43899` = c(2, 4.2, 0.6), | ||
`43906` = c(1, 3.2, 0.5), | ||
`43913` = c(2, 4.2, 0.6) | ||
), | ||
month = tibble::tibble( | ||
ref = c("1", "2", "3"), | ||
measure_name = c("M1", "M2", "M3"), | ||
comment = c("comment", "comment", "comment"), | ||
`43831` = c(1, 3.2, 0.5), | ||
`43862` = c(2, 4.2, 0.6), | ||
`43891` = c(1, 3.2, 0.5), | ||
`43922` = c(2, 4.2, 0.6), | ||
`43952` = c(1, 3.2, 0.5), | ||
`43983` = c(2, 4.2, 0.6), | ||
`44013` = c(1, 3.2, 0.5), | ||
`44044` = c(2, 4.2, 0.6), | ||
`44075` = c(1, 3.2, 0.5), | ||
`44105` = c(2, 4.2, 0.6), | ||
`44136` = c(1, 3.2, 0.5), | ||
`44166` = c(2, 4.2, 0.6) | ||
) | ||
) | ||
|
||
report_config <- tibble::tibble( | ||
ref = c("1", "2", "3", "1", "2", "3"), | ||
measure_name = c("M1", "M2", "M3", "M1", "M2", "M3"), | ||
domain = c("D1", "D1", "D1", "D2", "D2", "D2"), | ||
aggregation = c("week", "week", "week", "month", "month", "month") | ||
) | ||
|
||
|
||
"it returns true when all required data is present" |> | ||
test_that({ | ||
expect_equal( | ||
spcr_check_dataset_is_complete(report_config, measure_data), | ||
TRUE | ||
) | ||
}) | ||
|
||
"it errors when insufficient data has been supplied" |> | ||
test_that({ | ||
# remove the monthly data | ||
measure_data[["month"]] <- NULL | ||
|
||
expect_error( | ||
spcr_check_dataset_is_complete(report_config, measure_data), | ||
"spcr_check_dataset_is_complete: Data is missing for 3 report items. The first is ref 1, M1, monthly." | ||
) | ||
}) |
Oops, something went wrong.