Skip to content
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

Expand suggest_dataset_name to potentially suggest multiple datasets names #28

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions R/suggest_dataset_name.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ 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.}"
))
}

# 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}}?"
))
}
2 changes: 1 addition & 1 deletion tests/testthat/test-get_dataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.+?\\?"
)
})
9 changes: 8 additions & 1 deletion tests/testthat/test-suggest_dataset_names.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 .+?\\?"
)
})
Loading