-
Notifications
You must be signed in to change notification settings - Fork 2
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
add error message for missing strata #227
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this PR; please address comments and add tests for the code lines in this PR.
R/est.incidence.by.R
Outdated
cli::cli_abort( | ||
class = "missing_var", | ||
message = c( | ||
"Can't find the column {.var {strata}} in {.envvar pop_data}.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please revise this inline markup; pop_data
is a function argument, not an environment variable (see https://cli.r-lib.org/reference/inline-markup.html)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is well-noted.
R/est.incidence.by.R
Outdated
if (length(strata_var) > 0) { | ||
"i" <- "Did you mean {.var {strata_var}}." | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add a test that covers this case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been implemented.
R/est.incidence.by.R
Outdated
@@ -101,6 +101,27 @@ est.incidence.by <- function( | |||
return(to_return) | |||
} | |||
|
|||
if (!any(is.element(strata,pop_data %>% names()))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please always format according to the style guide (add a space after the comma in strata,pop_data
, etc)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change has been made.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting closer; please see inline comments.
R/est.incidence.by.R
Outdated
@@ -101,6 +101,27 @@ est.incidence.by <- function( | |||
return(to_return) | |||
} | |||
|
|||
if (!any(is.element(strata, pop_data %>% names()))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should any()
be all()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be all()
. The change has been made.
R/est.incidence.by.R
Outdated
grep( | ||
x = pop_data %>% names(), | ||
value = TRUE, | ||
pattern = strata, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens here if strata
has multiple entries in it? for example, strata = c("Country", "catch")
? Please check this scenario and adjust this code if needed (probably, try to match each missing stratum variable separately).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is in order and adds complexity to Issue #233. For example, if strata = c("age", "Country")
, I had opted to use regex paste0("^", strata)
to capture only columns that begin with age
to avoid and avoid words such as village.
Addendum:
Never mind, I found a solution to it.
R/est.incidence.by.R
Outdated
message = c( | ||
"Can't find the column {.arg {strata}} in {.arg pop_data}.", | ||
if (length(strata_var) > 0) { | ||
"i" <- "Did you mean {.var {strata_var}}." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please end questions with a question mark instead of a period.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been implemented.
R/est.incidence.by.R
Outdated
cli::cli_abort( | ||
class = "missing_var", | ||
message = c( | ||
"Can't find the column {.arg {strata}} in {.arg pop_data}.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please inform the user that this error relates to their input for the strata
argument, so they know which input to fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been implemented.
…ithub.com/UCD-SERG/serocalculator into add-user-error-message-for-missing-strata
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the hard work on this PR; please see inline comments.
R/est.incidence.by.R
Outdated
@@ -101,6 +101,36 @@ est.incidence.by <- function( | |||
return(to_return) | |||
} | |||
|
|||
if (!all(is.element(strata, pop_data %>% names()))) { | |||
# accommodate multiple strata | |||
combined_pattern <- paste(strata, collapse = "|") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach seems sub-optimal, for two reasons:
- we won't be able to tell which columns partially match each specific missing element of
strata
. - we didn't remove the elements of
strata
that already exactly match columns inpop_data
More generally, complicated regular expressions are a recipe for bugs; if you think you need to use |
in a regex, please carefully consider alternative approaches. As always, we want to keep the code as simple as possible; for example, in this case, instead of pasting strata
together, we could instead individually grep each element of strata
that isn't exactly in pop_data
, using a for
loop, or lapply()
, or purrr::map()
, etc.
Then, we can report the possible partial matches for each missing element of strata
; the markup capabilities of cli_abort()
enable us to provide this information in an orderly, structured format. Please give all this a try, but if you get stuck, just let me know and I'll provide more detailed instructions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have made changes to this approach to capture full match, partial match and no match.
tests/testthat/test-est.incidence.R
Outdated
curve <- load_curve_params("https://osf.io/download/rtw5k/") | ||
|
||
expect_error( | ||
object = est.incidence.by( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are we testing est.incidence.by()
in the test file for est.incidence()
? Please be careful to keep these tests properly organized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add a test in which strata
contains multiple elements that don't exactly match the columns of pop_data
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have separated est.incidence
and est.incidence.by
into different scripts. In addition, I have added a test for multiple strata
in est.incidence.by
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this PR is still in-progress?
-
Please address the lint errors and restore the files that seem to have been accidentally deleted.
-
Before re-requesting review, please look through Files changed and add at least one comment per changed file: briefly explain what's been changed and why.
…culator into simplifications
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this work; please see comments below and suggested edits in #245
NEWS.md
Outdated
@@ -1,4 +1,7 @@ | |||
# serocalculator (development version) | |||
# serocalculator 1.3.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see comment in previous review; this change still needs to be reverted
Co-authored-by: Douglas Ezra Morrison <demorrison@ucdavis.edu>
Co-authored-by: Douglas Ezra Morrison <demorrison@ucdavis.edu>
…ithub.com/UCD-SERG/serocalculator into add-user-error-message-for-missing-strata
more edits to est.incidence.by()
…ithub.com/UCD-SERG/serocalculator into add-user-error-message-for-missing-strata
No description provided.