-
Notifications
You must be signed in to change notification settings - Fork 6
99 create var from codelist bugfix #102
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
base: main
Are you sure you want to change the base?
Conversation
|
@bms63 Could you take a look at this one please |
Merge branch '99-create-var-from-codelist-bugfix' of github.com:pharmaverse/metatools into 99-create-var-from-codelist-bugfix # Please enter a commit message to explain why this merge is necessary, # especially if it merges an updated upstream into a topic branch. # # Lines starting with '#' will be ignored, and an empty message aborts # the commit.
| create_var_from_codelist( | ||
| data = data, | ||
| metacore = adlb_spec, | ||
| input_var = PARAMCD, | ||
| out_var = PARAM, | ||
| codelist = get_control_term(adlb_spec, PARAMCD), | ||
| decode_to_code = FALSE, | ||
| strict = TRUE | ||
| ) |> | ||
| expect_warning() |
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.
when i run this as standalone I am not getting a warning
> load(metacore::metacore_example("pilot_ADaM.rda"))
> adlb_spec <- metacore::select_dataset(metacore, "ADLBC", quiet = TRUE)
✔ ADLBC dataset successfully selected
ℹ Dataset metadata specification subsetted with suppressed warnings
> data <- tibble::tibble(
+ PARAMCD = c("ALB", "ALP", "ALT", "DUMMY", "DUMMY2")
+ )
> compare <- tibble::tibble(
+ PARAMCD = c("ALB", "ALP", "ALT", "DUMMY", "DUMMY2"),
+ PARAM = c("Albumin (g/L)", "Alkaline Phosphatase (U/L)", "Alanine Aminotransferase (U/L)", NA, NA)
+ )
>
> create_var_from_codelist(
+ data = data,
+ metacore = adlb_spec,
+ input_var = PARAMCD,
+ out_var = PARAM,
+ codelist = get_control_term(adlb_spec, PARAMCD),
+ decode_to_code = FALSE,
+ strict = FALSE
+ )
# A tibble: 5 × 2
PARAMCD PARAM
<chr> <chr>
1 ALB Albumin (g/L)
2 ALP Alkaline Phosphatase (U/L)
3 ALT Alanine Aminotransferase (U/L)
4 DUMMY NA
5 DUMMY2 NA
>
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.
however the tests run fine - but im a bit suspicious
| metacore = adlb_spec, | ||
| input_var = PARAMCD, | ||
| out_var = PARAM, | ||
| codelist = get_control_term(adlb_spec, PARAMCD), |
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.
| codelist = get_control_term(adlb_spec, PARAMCD), | |
| codelist = metacore::get_control_term(adlb_spec, PARAMCD), |
I thought this was from metatools at first and got confused...maybe be more explicit here with the :: for those who come later?
| data3 <- tibble::tibble( | ||
| PARAMN = c(18, 19, 20, 99, 999) | ||
| ) | ||
|
|
||
| create_var_from_codelist( | ||
| data = data3, | ||
| metacore = adlb_spec, | ||
| input_var = PARAMN, | ||
| out_var = PARAM, | ||
| codelist = get_control_term(adlb_spec, PARAMN), | ||
| decode_to_code = FALSE, | ||
| strict = TRUE | ||
| ) |> |
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 one produced the warning when I fired off in the console
> # Test numeric variable used as input_var / multiple issue case (strict == TRUE)
> data3 <- tibble::tibble(
+ PARAMN = c(18, 19, 20, 99, 999)
+ )
>
> create_var_from_codelist(
+ data = data3,
+ metacore = adlb_spec,
+ input_var = PARAMN,
+ out_var = PARAM,
+ codelist = get_control_term(adlb_spec, PARAMN),
+ decode_to_code = FALSE,
+ strict = TRUE
+ )
# A tibble: 5 × 2
PARAMN PARAM
<dbl> <chr>
1 18 Sodium (mmol/L)
2 19 Potassium (mmol/L)
3 20 Chloride (mmol/L)
4 99 NA
5 999 NA
Warning message:
In `create_var_from_codelist()`: The following values present in the input dataset are not present in the
codelist: 99 and 999
Closes #99
This bug occurred only when there were multiple values from a numeric type input column that were not present in the codelist i.e., values of 99 and 999 in the dataset but no appropriate record in the CT.
The fix just required placing a
cli::qty()check prior to the glue substitution that uses pluralization.This wasn't caught in testing because the test case only had a single value of wrong CT in the test dataset. I have expanded the test cases to include both single and multiple bad CT for both character and numeric input.