From e7459daeea7817df2605b6f45978db700e416afb Mon Sep 17 00:00:00 2001 From: James McMahon Date: Thu, 18 Apr 2024 17:44:38 +0100 Subject: [PATCH 1/3] Fix a typo in the error message --- R/suggest_dataset_name.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/suggest_dataset_name.R b/R/suggest_dataset_name.R index 0a61cbe..62a1f0d 100644 --- a/R/suggest_dataset_name.R +++ b/R/suggest_dataset_name.R @@ -17,7 +17,7 @@ suggest_dataset_name <- function(dataset_name) { "Can't find the dataset name {.var {dataset_name}}, or a close match.", i = "Find a dataset's name in the URL - of it's page on {.url www.opendata.nhs.scot.}" + of its page on {.url www.opendata.nhs.scot.}" )) } From 15549c4ec8bc9bc75a56c1e26985d07f16cfcc45 Mon Sep 17 00:00:00 2001 From: James McMahon Date: Thu, 18 Apr 2024 17:47:49 +0100 Subject: [PATCH 2/3] Expand `suggest_dataset_name` to potentially suggest multiple I noticed that for the prompt `populations` it was suggesting `hospital-codes`, this was because there were multiple 'options' that were equally 'close'. This tweak allows suggesting any amount when many are equally close. I don't think `hospital-codes` is at all a good suggestion for `populations` but to fix that we'd have to change how it works out the string distances (e.g. change the `method`). --- R/suggest_dataset_name.R | 4 ++-- tests/testthat/test-suggest_dataset_names.R | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/R/suggest_dataset_name.R b/R/suggest_dataset_name.R index 62a1f0d..f59aab7 100644 --- a/R/suggest_dataset_name.R +++ b/R/suggest_dataset_name.R @@ -22,11 +22,11 @@ suggest_dataset_name <- function(dataset_name) { } # find closet match - closest_match <- dataset_names[which.min(string_distances)] + closest_match <- dataset_names[which(string_distances == min(string_distances))] # throw error with suggestion cli::cli_abort(c( "Can't find the dataset name {.var {dataset_name}}.", - "i" = "Did you mean '{closest_match}'?" + "i" = "Did you mean {?any of }{.val {closest_match}}?" )) } diff --git a/tests/testthat/test-suggest_dataset_names.R b/tests/testthat/test-suggest_dataset_names.R index 9305c6c..fe68999 100644 --- a/tests/testthat/test-suggest_dataset_names.R +++ b/tests/testthat/test-suggest_dataset_names.R @@ -12,6 +12,13 @@ test_that("throws error and does suggest for close matches", { phsopendata:::suggest_dataset_name( "rospital-codes" ), - regexp = "Did you mean 'hospital-codes'?" + regexp = "Did you mean .+?\\?" + ) + + expect_error( + suggest_dataset_name( + "population" + ), + regexp = "Did you mean any of .+?\\?" ) }) From a04621433a004d5d02f4d1a2cd24837e95889ea9 Mon Sep 17 00:00:00 2001 From: James McMahon Date: Thu, 18 Apr 2024 18:01:01 +0100 Subject: [PATCH 3/3] Update test-get_dataset.R --- tests/testthat/test-get_dataset.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-get_dataset.R b/tests/testthat/test-get_dataset.R index cab33b0..5c21441 100644 --- a/tests/testthat/test-get_dataset.R +++ b/tests/testthat/test-get_dataset.R @@ -18,6 +18,6 @@ test_that("errors properly", { regexp = "Can't find the dataset name `dataset-name-with-no-close-match`" ) expect_error(get_dataset("gp-practice-population"), - regexp = "Did you mean 'gp-practice-populations'?" + regexp = "Did you mean .+?gp-practice-populations.+?\\?" ) })