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

check_type in derive_vars_merged() not working #2326

Closed
kaz462 opened this issue Feb 6, 2024 · 7 comments · Fixed by #2345
Closed

check_type in derive_vars_merged() not working #2326

kaz462 opened this issue Feb 6, 2024 · 7 comments · Fixed by #2345
Assignees
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers

Comments

@kaz462
Copy link
Collaborator

kaz462 commented Feb 6, 2024

Background Information

check_type in derive_vars_merged() is not working as expected when order is NULL
example: check_type = warning but an error is returned

adsl <- tribble(
  ~USUBJID, ~SEX, ~COUNTRY,
  "ST42-1", "F",  "AUT"
)

advs <- tribble(
  ~USUBJID, ~PARAMCD, ~AVISIT,    ~AVISITN, ~AVAL,
  "ST42-1", "WEIGHT", "BASELINE",        0,    66,
  "ST42-1", "WEIGHT", "WEEK 2",          1,    68
)

derive_vars_merged(
  adsl,
  dataset_add = advs,
  by_vars = exprs(USUBJID),
  new_vars = exprs(WEIGHT = AVAL),
  check_type = "warning"
)

error message:

Error in `signal_duplicate_records()`:
! Dataset `dataset_add` contains duplicate records with respect to `USUBJID`
Run `get_duplicates_dataset()` to access the duplicate records
Run `rlang::last_trace()` to see where the error occurred.

Definition of Done

add cnd_type = check_type when calling the following signal_duplicate_records

admiral/R/derive_merged.R

Lines 375 to 379 in 16671ee

signal_duplicate_records(
add_data,
by_vars = by_vars_right,
msg = duplicate_msg
)

@kaz462 kaz462 added bug Something isn't working good first issue Good for newcomers labels Feb 6, 2024
@Lina2689 Lina2689 self-assigned this Feb 19, 2024
@Lina2689
Copy link
Contributor

Hi @kaz462 , after adding cnd_type = check_type to signal_duplicate_records call, its working and throwing warning message when check_type = "warning" . Should I update this and create PR?
image

@bundfussr
Copy link
Collaborator

Hi @kaz462 , hi @Lina2689 , it is intended that an error is issued regardless of check_type if order is not specified. derive_vars_merged() should add variables but it shouldn't change the number of records. If there is more than one record per by group in dataset_add (after filtering), the left_join() in line 419, would add records to the input dataset. If order is specified, this can not happen because the filter_extreme() call in line 361 ensures that there is not more than one records per by group.

So please do not change the code.

@kaz462
Copy link
Collaborator Author

kaz462 commented Feb 19, 2024

@bundfussr @Lina2689 Thanks both for looking into it. Should we add documentation regarding the behavior of the check_type argument? If the order argument is not specified, the check_type argument is ignored.

@bms63 bms63 added documentation Improvements or additions to documentation and removed bug Something isn't working labels Feb 19, 2024
@bms63
Copy link
Collaborator

bms63 commented Feb 19, 2024

I think we should update the documentation for the arguments. @Lina2689 do you mind doing this?

@Lina2689
Copy link
Contributor

Sure @bms63. and thanks for clarifying the issue.

@Lina2689
Copy link
Contributor

@bms63 , do I need to update/modify both vignette and information in the function header documentation?

@bms63
Copy link
Collaborator

bms63 commented Feb 20, 2024

@bms63 , do I need to update/modify both vignette and information in the function header documentation?

Yes please! Where ever the arguments are discussed it should be updated. If not discussed in the https://pharmaverse.github.io/admiral/articles/generic.html then I think it warrants an inclusion

@Lina2689 Lina2689 linked a pull request Feb 22, 2024 that will close this issue
15 tasks
Lina2689 added a commit that referenced this issue Feb 23, 2024
bms63 pushed a commit that referenced this issue Mar 4, 2024
#2345)

* check_type documentation is updated for argument details.

* #2326 Updated the description.

* Updates to add test cases when order is not specified and updated the decription.

* Updates for code styler.

* Updated error message.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers
Development

Successfully merging a pull request may close this issue.

4 participants