diff --git a/DESCRIPTION b/DESCRIPTION index 14500a7..5d58c7e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: SPCreporter Title: Creates Metric Reports using Statistical Process Control in the NHS style -Version: 0.1.0 +Version: 0.1.1 Authors@R: person("Tom", "Smith", , "tomsmith_uk@hotmail.com", role = c("aut", "cre")) Description: Takes a dataset file and a configuration file to produce an html diff --git a/NEWS.md b/NEWS.md index 0e0860e..fe28a26 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,11 @@ -# SPCreporter 0.1.0 +# SPCreporter 0.1.1 + +## Bugfix + +* Fixes an error occurring when targets are not set for any of the reported measures + +# SPCreporter 0.1.0 ## Initial Release * spcr_make_data_bundle() diff --git a/R/spcr_calculate_row.R b/R/spcr_calculate_row.R index 3342d41..cea8354 100644 --- a/R/spcr_calculate_row.R +++ b/R/spcr_calculate_row.R @@ -67,12 +67,19 @@ spcr_calculate_row <- function(ref, aggregation, measure_data, measure_config, r x_date_format <- dplyr::if_else(aggregation == "week", "%d-%b-%Y", "%b '%y") + # ptd_spc function needs NULL for target when no target is set + if(is.na(target)){ + spc_target <- NULL + } else { + spc_target <- target + } + # do the SPC calcs and store the results spc <- NHSRplotthedots::ptd_spc( subset_measure_data, value_field = "value", date_field = "date", - target = target, + target = spc_target, # set to NULL in code if NA in source data # fix_after_n_points = #TODO improvement_direction = tolower(improvement_direction) ) diff --git a/tests/testthat/test-spcr_make_data_bundle.R b/tests/testthat/test-spcr_make_data_bundle.R index d272b0b..29a172e 100644 --- a/tests/testthat/test-spcr_make_data_bundle.R +++ b/tests/testthat/test-spcr_make_data_bundle.R @@ -72,3 +72,21 @@ test_that("it returns a dataframe of the expected size", { 25 ) }) + +test_that("it works when no targets are set", { + + # replace all targets with NA, as if not set + measure_config$target <- NA + + r <- spcr_make_data_bundle(measure_data, report_config, measure_config) + + expect_equal( + nrow(r), + 6 + ) + + expect_equal( + ncol(r), + 25 + ) +})